1 INTEL 80286 PROGRAMMER'S REFERENCE MANUAL 1987
3 Intel Corporation makes no warranty for the use of its products and
4 assumes no responsibility for any errors which may appear in this document
5 nor does it make a commitment to update the information contained herein.
7 Intel retains the right to make changes to these specifications at any
10 Contact your local sales office to obtain the latest specifications before
13 The following are trademarks of Intel Corporation and may only be used to
14 identify Intel Products:
16 Above, BITBUS, COMMputer, CREDIT, Data Pipeline, FASTPATH, Genius, i, î,
17 ICE, iCEL, iCS, iDBP, iDIS, I²ICE, iLBX, im, iMDDX, iMMX, Inboard, Insite,
18 Intel, intel, intelBOS, Intelevision, inteligent Identifier, inteligent
19 Programming, Intellec, Intellink, iOSP, iPDS, iPSC, iRMX, iSBC, iSBX, iSDM,
20 iSXM, KEPROM, Library Manager, MAP-NET, MCS, Megachassis, MICROMAINFRAME,
21 MULTIBUS, MULTICHANNEL, MULTIMODULE, MultiSERVER, ONCE, OpenNET, OTP,
22 PC-BUBBLE, Plug-A-Bubble, PROMPT, Promware, QUEST, QueX, Quick-Pulse
23 Programming, Ripplemode, RMX/80, RUPI, Seamless, SLD, UPI, and VLSiCEL, and
24 the combination of ICE, iCS, iRMX, iSBC, iSBX, MCS, or UPI and a numerical
27 MDS is an ordering code only and is not used as a product name or
28 trademark. MDS(R) is a registered trademark of Mohawk Data Sciences
31 *MULTIBUS is a patented Intel bus.
33 Additional copies of this manual or other Intel literature may be obtained
37 Literature Distribution
42 (c)INTEL CORPORATION 1987 CG-10/86
47 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
50 This manual describes the 80286, the most powerful 16-bit microprocessor in
51 the 8086 family, and the 80287 Numeric Processor Extension (NPX).
53 Organization of This Manual
57 The 80286 contains a table of contents, eleven chapters, four appendices,
58 and an index. For more information on the 80286 book's organization, see its
59 first chapter, Chapter 1, "Introduction to the 80286." Section 1.4 in that
60 chapter explains the organization in detail.
62 Notational Conventions
63 This manual uses special notation to represent sub- and superscript
64 characters. Subscript characters are surrounded by {curly brackets}, for
65 example 10{2} = 10 base 2. Superscript characters are preceeded by a caret
66 and enclosed within (parentheses), for example 10^(3) = 10 to the third
71 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
74 Chapter 1 Introduction to the 80286
76 1.1 General Attributes
77 1.2 Modes of Operation
79 1.3.1 Memory Management
81 1.3.3 Protection Mechanisms
82 1.3.4 Support for Operating Systems
84 1.4 Organization of This Book
85 1.5 Related Publications
87 Chapter 2 80286 Base Architecture
89 2.1 Memory Organization and Segmentation
92 2.3.1 General Registers
93 2.3.2 Memory Segmentation and Segment Registers
94 2.3.3 Index, Pointer, and Base Registers
95 2.3.4 Status and Control Registers
99 2.4.2 Register and Immediate Modes
100 2.4.3 Memory Addressing Modes
101 2.4.3.1 Segment Selection
102 2.4.3.2 Offset Computation
106 2.5.1 I/O Address Space
107 2.5.2 Memory-Mapped I\0
109 2.6 Interrupts and Exceptions
110 2.7 Hierarchy of Instruction Sets
112 Chapter 3 Basic Instruction Set
114 3.1 Data Movement Instructions
115 3.1.1 General-Purpose Data Movement Instructions
116 3.1.2 Stack Manipulation Instructions
118 3.2 Flag Operation with the Basic Instruction Set
120 3.2.2 Control Flags 4
122 3.3 Arithmetic Instructions
123 3.3.1 Addition Instructions
124 3.3.2 Subtraction Instructions
125 3.3.3 Muitiplication Instructions
126 3.3.4 Division Instructions
128 3.4 Logical Instructions
129 3.4.1 Boolean Operation Instructions
130 3.4.2 Shift and Rotate Instructions
131 3.4.2.1 Shift Instructions
132 3.4.2.2 Rotate Instructions
134 3.4.3 Type Conversion and No-Operation Instructions
136 3.5 Test and Compare Instructions
137 3.6 Control Transfer Instructions
138 3.6.1 Unconditional Transfer Instructions
139 3.6.1.1 Jump instruction
140 3.6.1.2 Call Instruction
141 3.6.1.3 Return and Return from interrupt Instruction
143 3.6.2 Conditional Transfer Instructions
144 3.6.2.1 Conditional Jump Instructions
145 3.6.2.2 Loop Instructions
146 3.6.2.3 Executing a Loop or Repeat Zero Times
148 3.6.3 Software-Generated Interrupts
149 3.6.3.1 Software Interrupt Instruction
151 3.7 Character Translation and String Instructions
152 3.7.1 Translate Instruction
153 3.7.2 String Manipulation Instructions and Repeat Prefixes
154 3.7.2.1 String Movement Instructions
155 3.7.2.2 Other String Operations
157 3.8 Address Manipulation Instructions
158 3.9 Flag Control instructions
159 3.9.1 Carry Flag Control Instructions
160 3.9.2 Direction Flag Control Instructions
161 3.9.3 Flag Transfer Instructions
163 3.10 Binary-Coded Decimal Arithmetic Instructions
164 3.10.1 Packed BCD Adjustment Instructions
165 3.10.2 Unpacked BCD Adjustment Instructions
167 3.11 Trusted Instructions
168 3.11.1 Trusted and Privileged Restrictions on POPF and IRET
169 3.11.2 Machine State Instructions
170 3.11.3 Inputand Output Instructions
172 3.12 Processor Extension Instructions
173 3.12.1 Processor Extension Synchronization Instructions
174 3.12.2 Numeric Data Processor Instructions
175 3.12.2.1 Arithmetic Instructions
176 3.12.2.2 Comparison Instructions
177 3.12.2.3 Transcendental Instructions
178 3.12.2.4 Data Transfer Instructions
179 3.12.2.5 Constant Instructions
181 Chapter 4 Extended Instruction Set
183 4.1 Block I\O Instructions
184 4.2 High-Level Instructions
186 Chapter 5 Real Address Mode
188 5.1 Addressing and Segmentation
189 5.2 Interrupt Handling
190 5.2.1 Interrupt Vector Table
191 5.2.1.1 Interrupt Procedures
192 5.2.2 Interrupt Priorities
193 5.2.3 Reserved and Dedicated Interrupt Vectors
195 5.3 System Initialization.
197 Chapter 6 Memory Management and Virtual Addressing
199 6.1 Memory Management Overview
200 6.2 Virtual Addresses
201 6.3 Descriptor Tables
202 6.4 Virtual-to-Physical Address Translation
203 6.5 Segments and Segment Descriptors
204 6.6 Memory Management Registers
205 6.6.1 Segment Address Translation Registers
206 6.6.2 System Address Registers
211 7.1.1 Types of Protection
212 7.1.2 Protection Implementation
214 7.2 Memory Management and Protection
215 7.2.1 Separation of Address Spaces
216 7.2.2 LDT and GDT Access Checks
217 7.2.3 Type Validation
219 7.3 Privilege Levels and Protection
220 7.3.1 Example of Using Four Privilege Levels
221 7.3.2 Privilege Usage
223 7.4 Segment Descriptor
225 7.4.2 Code Segment Access
226 7.4.3 Data Access Restriction by Privilege Level
227 7.4.4 Pointer Privilege Stamping via ARPL
229 7.5 Control Transfers
232 7.5.1.2 Intra-Level Transfers via Call Gate
233 7.5.1.3 Inter-Level Control Transfer via Call Gates
234 7.5.1.4 Stack Changes Caused by Call Gates
236 7.5.2 Inter-Level Returns
238 Chapter 8 Tasks and State Transitions
241 8.2 Task State Segments and Descriptors
242 8.2.1 Task State Segment Descriptors
248 Chapter 9 Interrupts and Exceptions
250 9.1 Interrupt Descriptor Table
251 9.2 Hardware Initiated Interrupts
252 9.3 Software Initiated Interrupts
253 9.4 Interrupt Gates and Trap Gates
254 9.5 Task Gates and Interrupt Tasks
255 9.5.1 Scheduling Considerations
256 9.5.2 Deciding Between Task, Trap, and Interrupt Gates
258 9.6 Protection Exceptions and Reserved Vectors
259 9.6.1 Invalid OP-Code (Interrupt 6)
260 9.6.2 Double Fault (Interrupt 8)
261 9.6.3 Processor Extension Segment Overrun (Interrupt 9)
262 9.6.4 Invalid Task State Segment (Interrupt 10)
263 9.6.5 Not Present (Interrupt 11)
264 9.6.6 Stack Fault (Interrupt 12)
265 9.6.7 General Protection Fault (Interrupt 13)
267 9.7 Additional Exceptions and Interrupts
268 9.7.1 Single Step Interrupt (Interrupt 1)
270 Chapter 10 System Control and Initialization
272 10.1 System Flags and Registers
273 10.1.1 Descriptor Table Registers
275 10.2 System Control Instructions
276 10.2.1 Machine Status Word
277 10.2.2 Other Instructions
279 10.3 Privileged and Trusted Instructions
282 10.4.1 Real Address Mode
283 10.4.2 Protected Mode
285 Chapter 11 Advanced Topics
287 11.1 Virtual Memory Management
288 11.2 Special Segment Attributes
289 11.2.1 Conforming Code Segments
290 11.2.2 Expand-Down Data Segments
292 11.3 Pointer Validation
293 11.3.1 Descriptor Validation
294 11.3.2 Pointer Integrity: RPL and the"Trojan Horse Problem"
296 11.4 NPX Context Switching
297 11.5 Multiprocessor Considerations
300 Appendix A 80286 System Initialization
302 Appendix B The 80286 Instruction Set
304 Appendix C 8086/8088 Compatibility Considerations
306 Appendix D 80286/80386 Software Compatibility Considerations
312 1-1 Four Privilege Levels
314 2-1 Segmented Virtual Memory
315 2-2 Bytes and Words in Memory.
316 2-3 80286/80287 Supported Data Types
317 2-4 80286 Base Architecture Register Set
318 2-5 Real Address Mode Segment Selector Interpretation
319 2-6 Protected Mode Segment Selector Interpretation
322 2-9 BP Usage as a Stack Frame Base Pointer
324 2-11 Two-Component Address
325 2-12 Use of Memory Segmentation
326 2-13 Complex Addressing Modes
327 2-14 Memory-Mapped I/O
328 2-15 Hierarchy of Instructions
334 3-5 Flag Word Contents
345 4-1 Formal Definition of the ENTER Instruction
346 4-2 Variable Access in Nested Procedures
347 4-2a Stack Frame for MAIN at Level 1
348 4-2b Stack Frame for Procedure A
349 4-2c Stack Frame for Procedure B at Level 3 Called from A
350 4-2d Stack Frame for Procedure C at Level 3 Called from B
352 5-1a Forming the Segment Base Address
353 5-1b Forming the 20-Bit Physical Address in the Real Address Mode
354 5-2 Overlapping Segments to Save Physical Memory
355 5-3 Interrupt Vector Table for Real Address Mode
356 5-4 Stack Structure after Interrupt (Real Address Mode)
358 6-1 Format of the Segment Selector Component
359 6-2 Address Spaces and Task Isolation
360 6-3 Segment Descriptor (S=1)
361 6-4 Special Purpose Descriptors or System Segment Descriptors (S=O)
363 6-6 Virtual-to-Physical Address Translation
364 6-7 Segment Descriptor Access Bytes
365 6-8 Memory Management Registers
366 6-9 Descriptor Loading
368 7-1 Addressing Segments of a Module within a Task
369 7-2 Descriptor Cache Registers
370 7-3 80286 Virtual Address Space
371 7-4 Local and Global Descriptor Table Definitions
372 7-5 Error Code Format (on the stack)
373 7-6 Code and Data Segments Assigned to a Privilege Level.
375 7-8 Access Byte Examples.
376 7-9 Pointer Privilege Stamping
377 7-10 Gate Descriptor Format.
379 7-12 Stack Contents after an Inter-Level Call
381 8-1 Task State Segment and TSS Registers
383 8-3 Task Gate Descriptor
384 8-4 Task Switch Through a Task Gate
386 9-1 Interrupt Descriptor Table Definition
387 9-2 IDT Selector Error Code.
388 9-3 Trap/Interrupt Gate Descriptors
389 9-4 Stack Layout after an Exception with an Error Code
391 10-1 Local and Global Descriptor Table Definition
392 10-2 Interrupt Descriptor Table Definition
393 10-3 Data Type for Global Descriptor Table and Interrupt Descriptor Table
395 11-1 Expand-Down Segment
396 11-2 Dynamic Segment Relocation and Expansion of Segment Limit
397 11-3 Example of NPX Context Switching
399 B-1 /n Instruction Byte Format
400 B-2 /r Instruction Byte Format
404 2-1 Implied Segment Usage by Index, Pointer, and Base Registers
405 2-2 Segment Register Selection Rules
406 2-3 Memory Operand Addressing Modes
407 2-4 80286 Interrupt Vector Assignments (Real Address Mode)
409 3-1 Status Flags' Functions
410 3-2 Control Flags' Functions
411 3-3 Interpretation of Conditional Transfers
413 5-1 Interrupt Processing Order
414 5-2 Dedicated and Reserved Interrupt Vectors in Real Address Mode
415 5-3 Processor State after RESET
417 7-1 Segment Access Rights Byte Format
418 7-2 Allowed Segment Types in Segment Registers
420 7-4 Inter-Level Return Checks
422 8-1 Checks Made during a Task Switch
423 8-2 Effect of a Task Switch on BUSY and NT Bits and the Link Word
425 9-1 Trap and Interrupt Gate Checks
426 9-2 Interrupt and Gate Interactions
427 9-3 Reserved Exceptions and Interrupts
428 9-4 Interrupt Processing Order
429 9-5 Conditions That Invalidate the TSS
431 10-1 MSW Bit Functions
432 10-2 Recommended MSW Encodings for Processor Extension Control
434 11-1 NPX Context Switching
437 B-2 Protection Exceptions of the 80286
438 B-3 Hexadecimal Values for the Access Rights Byte
440 C-1 New 80286 Interrupts
444 Chapter 1 Introduction to the 80286
446 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
448 The 80286 is the most powerful 16-bit processor in the 8086 series of
449 microprocessors, which includes the 8086, the 8088, the 80186, the 80188,
450 and the 80286. It is designed for applications that require very high
451 performance. It is also an excellent choice for sophisticated "high end"
452 applications that will benefit from its advanced architectural features:
453 memory management, protection mechanisms, task management, and virtual
454 memory support. The 80286 provides, on a single VLSI chip, computational
455 and architectural characteristics normally associated with much larger
458 Sections 1.1, 1.2, and 1.3 of this chapter provide an overview of the 80286
459 architecture. Because the 80286 represents an extension of the 8086
460 architecture, some of this overview material may be new and unfamiliar to
461 previous users of the 8086 and similar microprocessors. But the 80286 is
462 also an evolutionary development, with the new architecture superimposed
463 upon the industry standard 8086 in such a way as to affect only the design
464 and programming of operating systems and other such system software.
465 Section 1.4 of this chapter provides a guide to the organization of this
466 manual, suggesting which chapters are relevant to the needs of particular
470 1.1 General Attributes
472 The 80286 base architecture has many features in common with the
473 architecture of other members of the 8086 family, such as byte addressable
474 memory, I/O interfacing hardware, interrupt vectoring, and support for both
475 multiprocessing and processor extensions. The entire family has a common
476 set of addressing modes and basic instructions. The 80286 base architecture
477 also includes a number of extensions which add to the versatility of the
480 The 80286 processor can function in two modes of operation (see section 1.2
481 of this chapter, Modes of Operation). In one of these modes only the base
482 architecture is available to programmers, whereas in the other mode a number
483 of very powerful advanced features have been added, including support for
484 virtual memory, multitasking, and a sophisticated protection mechanism.
485 These advanced features are described in section 1.3 of this chapter.
487 The 80286 base architecture was designed to support programming in
488 high-level languages, such as Pascal, C or PL/M. The register set and
489 instructions are well suited to compiler-generated code. The addressing
490 modes (see section 2.4.3 in Chapter 2) allow efficient addressing
491 of complex data structures, such as static and dynamic arrays, records,
492 and arrays within records, which are commonly supported by high-level
493 languages. The data types supported by the architecture include, along with
494 bytes and words, high level language constructs such as strings, BCD, and
497 The memory architecture of the 80286 was designed to support modular
498 programming techniques. Memory is divided into segments, which may be of
499 arbitrary size, that can be used to contain procedures and data structures.
500 Segmentation has several advantages over more conventional linear memory
501 architectures. It supports structured software, since segments can contain
502 meaningful program units and data, and more compact code, since references
503 within a segment can be shorter (and locality of reference usually insures
504 that the next few references will be within the same segment). Segmentation
505 also lends itself to efficient implementation of sophisticated memory
506 management, virtual memory, and memory protection.
508 In addition, new instructions have been added to the base architecture to
509 give hardware support for procedure invocations, parameter passing, and
510 array bounds checking.
513 1.2 Modes of Operation
515 The 80286 can be operated in either of two different modes: Real Address
516 Mode or Protected Virtual Address Mode (also referred to as Protected Mode).
517 In either mode of operation, the 80286 represents an upwardly compatible
518 addition to the 8086 family of processors.
520 In Real Address Mode, the 80286 operates essentially as a very
521 high-performance 8086. Programs written for the 8086 or the 80186 can be
522 executed in this mode without any modification (the few exceptions are
523 described in Appendix C, "Compatibility Considerations"). Such upward
524 compatibility extends even to the object code level; for example, an 8086
525 program stored in read-only memory will execute successfully in 80286 Real
526 Address Mode. An 80286 operating in Real Address Mode provides a number of
527 instructions not found on the 8086. These additional instructions, also
528 present with the 80186, allow for efficient subroutine linkage, parameter
529 validation, index calculations, and block I/O transfers.
531 The advanced architectural features and full capabilities of the 80286 are
532 realized in its native Protected Mode. Among these features are
533 sophisticated mechanisms to support data protection, system integrity, task
534 concurrency, and memory management, including virtual storage.
535 Nevertheless, even in Protected Mode, the 80286 remains upwardly compatible
536 with most 8086 and 80186 application programs. Most 8086 applications
537 programs can be re-compiled or re-assembled and executed on the 80286 in
541 1.3 Advanced Features
543 The architectural features described in section 1.1 of this chapter
544 are common to both operating modes of the processor. In addition to these
545 common features, Protected Mode provides a number of advanced features,
546 including a greatly extended physical and logical address space, new
547 instructions, and support for additional hardware-recognized data
548 structures. The Protected Mode 80286 includes a sophisticated memory
549 management and multilevel protection mechanism. Full hardware support is
550 included for multitasking and task switching operations.
553 1.3.1 Memory Management
555 The memory architecture of the Protected Mode 80286 represents a
556 significant advance over that of the 8086. The physical address space has
557 been increased from 1 megabyte to 16 megabytes (2^(24) bytes), while the
558 virtual address space (i.e., the address space visible to a program) has
559 been increased from 1 megabyte to 1 gigabyte (2^(30) bytes). Moreover,
560 separate virtual address spaces are provided for each task in a
561 multi-tasking system (see the next section, 1.3.2, "Task Management").
563 The 80286 supports on-chip memory management instead of relying on an
564 external memory management unit. The one-chip solution is preferable because
565 no software is required to manage an external memory management unit,
566 performance is much better, and hardware designs are significantly simpler.
568 Mechanisms have been included in the 80286 architecture to allow the
569 efficient implementation of virtual memory systems. (In virtual memory
570 systems, the user regards the combination of main and external storage as a
571 single large memory. The user can write large programs without worrying
572 about the physical memory limitations of the system. To accomplish this, the
573 operating system places some of the user programs and data in external
574 storage and brings them into main memory only as they are needed.) All
575 instructions that can cause a segment-not-present fault are fully
576 restartable. Thus, a not-present segment can be loaded from external
577 storage, and the task can be restarted at the point where the fault
580 The 80286, like all members of the 8086 series, supports a segmented memory
581 architecture. The 80286 also fully integrates memory segmentation into a
582 comprehensive protection scheme. This protection scheme includes
583 hardware-enforced length and type checking to protect segments from
587 1.3.2 Task Management
589 The 80286 is designed to support multi-tasking systems. The architecture
590 provides direct support for the concept of a task. For example, task state
591 segments (see section 8.2 in Chapter 8) are hardware-recognized and
592 hardware-manipulated structures that contain information on the current
593 state of all tasks in the system.
595 Very efficient context-switching (task-switching) can be invoked with a
596 single instruction. Separate logical address spaces are provided for each
597 task in the system. Finally, mechanisms exist to support intertask
598 communication, synchronization, memory sharing, and task scheduling. Task
599 Management is described in Chapter 8.
602 1.3.3 Protection Mechanisms
604 The 80286 allows the system designer to define a comprehensive protection
605 policy to be applied, uniformly and continuously, to all ongoing operations
606 of the system. Such a policy may be desirable to ensure system reliability,
607 privacy of data, rapid error recovery, and separation of multiple users.
609 The 80286 protection mechanisms are based on the notion of a "hierarchy of
610 trust." Four privilege levels are distinguished, ranging from Level 0 (most
611 trusted) to Level 3 (least trusted). Level 0 is usually reserved for the
612 operating system kernel. The four levels may be visualized as concentric
613 rings, with the most privileged level in the center (see figure 1-1).
615 This four-level scheme offers system reliability, flexibility, and design
616 options not possible with the typical two-level (supervisor/user) separation
617 provided by other processors. A four-level division is capable of separating
618 kernel, executive, system services, and application software, each with
619 different privileges.
621 At any one time, a task executes at one of the four levels. Moreover, all
622 data segments and code segments are also assigned to privilege levels. A
623 task executing at one level cannot access data at a more privileged level,
624 nor can it call a procedure at a less privileged level (i.e., trust a less
625 privileged procedure to do work for it). Thus, both access to data and
626 transfer of control are restricted in appropriate ways.
628 A complete separation can exist between the logical address spaces local to
629 different tasks, providing users with automatic protection against
630 accidental or malicious interference by other users. The hardware also
631 provides immediate detection of a number of fault and error conditions, a
632 feature that can be useful in the development and maintenance of software.
634 Finally, these protection mechanisms require relatively little system
635 overhead because they are integrated into the memory management and
636 protection hardware of the processor itself.
639 Figure 1-1. Four Privilege Levels
641 ‚���������������������������ƒ
642 € LEVEL 3
\x11‘‘‘‘‘‘‘‘Α‘LEAST TRUSTED
643 € ‚���������������������ƒ €
645 € € ‚���������������ƒ € €
647 € € € ‚���������ƒ € € €
648 € € € € LEVEL 0 € € € €
650 € € € „�������Ï�… € € €
652 € € „����������Ï����… € €
654 € „�������������Ï�������… €
656 „����������������Ï����������…
661 1.3.4 Support for Operating Systems
663 Most operating systems involve some degree of concurrency, with multiple
664 tasks vying for system resources. The task management mechanisms described
665 above provide the 80286 with inherent support for such multi-tasking
666 systems. Moreover, the advanced memory management features of the 80286
667 allow the implementation of sophisticated virtual memory systems.
669 Operating system implementors have found that a multi-level approach to
670 system services provides better security and more reliable systems. For
671 example, a very secure kernel might implement critical functions such as
672 task scheduling and resource allocation, while less fundamental functions
673 (such asI/O) are built around the kernel. This layered approach also makes
674 program development and enhancement simpler and facilitates error detection
675 and debugging. The 80286 supports the layered approach through its
676 four-level privilege scheme.
679 1.4 Organization of This Book
681 To facilitate the use of this book both as an introduction to the 80286
682 architecture and as a reference guide, the remaining chapters are divided
683 into three major parts.
685 Part I, comprising chapters 2 through 4, should be read by all those who
686 wish to acquire a basic familiarity with the 80286 architecture. These
687 chapters provide detailed information on memory segmentation, registers,
688 addressing modes and the general (application level) 80286 instruction set.
689 In conjunction with the 80286 Assembly Language Reference Manual, these
690 chapters provide sufficient information for an assembly language programmer
691 to design and write application programs.
693 The chapters in Part I are:
695 Chapter 2, "Architectural Features." This chapter discusses those features
696 of the 80286 architecture that are significant for application programmers.
697 The information presented can also function as an introduction to the
698 machine for system programmers. Memory organization and segmentation,
699 processor registers, addressing modes, and instruction formats are all
702 Chapter 3, "Basic Instruction Set." This chapter presents the core
703 instructions of the 8086 family.
705 Chapter 4, "Extended Instruction Set." This chapter presents the extended
706 instructions shared by the 80186 and 80286 processors.
708 Part II of the book consists of a single chapter:
710 Chapter 5, "Real Address Mode." This chapter presents the system
711 programmer's view of the 80286 when the processor is operated in Real
714 Part III of the book comprises chapters 6 through 11. Aimed primarily at
715 system programmers, these chapters discuss the more advanced architectural
716 features of the 80286, which are available when the processor is in
717 Protected Mode. Details on memory management, protection mechanisms, and
718 task switching are provided.
720 The chapters in Part III are:
722 Chapter 6, "Virtual Memory." This chapter describes the 80286 address
723 translation mechanisms that support virtual memory. Segment descriptors,
724 global and local descriptor tables, and descriptor caches are discussed.
726 Chapter 7, "Protection." This chapter describes the protection features of
727 the 80286. Privilege levels, segment attributes, access restrictions, and
728 call gates are discussed.
730 Chapter 8, "Tasks and State Transitions." This chapter describes the 80286
731 mechanisms that support concurrent tasks. Context-switching, task state
732 segments, task gates, and interrupt tasks are discussed.
734 Chapter 9, "Interrupts, Traps and Faults." This chapter describes interrupt
735 and trap handling. Special attention is paid to the exception traps, or
736 faults, which may occur in Protected Mode. Interrupt gates, trap gates, and
737 the interrupt descriptor table are discussed.
739 Chapter 10, "System Control and Initialization." This chapter describes the
740 actual instructions used to implement the memory management, protection, and
741 task support features of the 80286. System registers, privileged
742 instructions, and the initial machine state are discussed.
744 Chapter 11, "Advanced Topics." This chapter completes Part III with a
745 description of several advanced topics, including special segment attributes
746 and pointer validation.
749 1.5 Related Publications
751 The following manuals also contain information of interest to programmers
754 Ž Introduction to the 80286, order number 210308
755 Ž ASM286 Assembly Language Reference Manual, order number 121924
756 Ž 80286 Operating System Writer's Guide, order number 121960
757 Ž 80286 Hardware Reference Manual, order number 210760
758 Ž Microprocessor and Peripheral Handbook, order number 230843
759 Ž PL/M-286 User's Guide, order number 121945
760 Ž 80287 Support Library Reference Manual, order number 122129
761 Ž 8086 Software Toolbox Manual, order number 122203 (includes
762 information about 80287 Emulator Software)
765 Chapter 2 80286 Base Architecture
767 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
769 This chapter describes the 80286 application programming environment as
770 seen by assembly language programmers. It is intended to introduce the
771 programmer to those features of the 80286 architecture that directly affect
772 the design and implementation of 80286 application programs.
775 2.1 Memory Organization and Segmentation
777 The main memory of an 80286 system makes up its physical address space.
778 This address space is organized as a sequence of 8-bit quantities, called
779 bytes. Each byte is assigned a unique address ranging from 0 up to a maximum
780 of 2^(20) (1 megabyte) in Real Address Mode, and up to 2^(24) (16 megabytes)
783 A virtual address space is the organization of memory as viewed by a
784 program. Virtual address space is also organized in units of bytes. (Other
785 addressable units such as words, strings, and BCD digits are described below
786 in section 2.2, "Data Types.") In Real Address Mode, as with the 8086
787 itself, programs view physical memory directly, inasmuch as they manipulate
788 pure physical addresses. Thus, the virtual address space is identical to the
789 physical address space (1 megabyte).
791 In Protected Mode, however, programs have no direct access to physical
792 addresses. Instead, memory is viewed as a much larger virtual address space
793 of 2^(30) bytes (1 gigabyte). This 1 gigabyte virtual address is mapped onto
794 the Protected Mode's 16-megabyte physical address space by the address
795 translation mechanisms described in Chapter 6.
797 The programmer views the virtual address space on the 80286 as a collection
798 of up to sixteen thousand linear subspaces, each with a specified size or
799 length. Each of these linear address spaces is called a segment. A segment
800 is a logical unit of contiguous memory. Segment sizes may range from one
801 byte up to 64K (65,536) bytes.
803 80286 memory segmentation supports the logical structure of programs and
804 data in memory. Programs are not written as single linear sequences of
805 instructions and data, but rather as modules of code and data. For example,
806 program code may include a main routine and several separate procedures.
807 Data may also be organized into various data structures, some private and
808 some shared with other programs in the system. Run-time stacks constitute
809 yet another data requirement. Each of these several modules of code and
810 data, moreover, may be very different in size or vary dynamically with
813 Segmentation supports this logical structure (see figure 2-1). Each
814 meaningful module of a program may be separately contained in individual
815 segments. The degree of modularization, of course, depends on the
816 requirements of a particular application. Use of segmentation benefits
817 almost all applications. Programs execute faster and require less space.
818 Segmentation also simplifies the design of structured software.
823 Bytes and words are the fundamental units in which the 80286 manipulates
824 data, i.e., the fundamental data types.
826 A byte is 8 contiguous bits starting on an addressable byte boundary. The
827 bits are numbered 0 through 7, starting from the right. Bit 7 is the most
831 ’‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘“
833 ”‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘•
835 A word is defined as two contiguous bytes starting on an arbitrary byte
836 boundary; a word thus contains 16 bits. The bits are numbered 0 through 15,
837 starting from the right. Bit 15 is the most significant bit. The byte
838 containing bit 0 of the word is called the low byte; the byte containing
839 bit 15 is called the high byte.
842 ’‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘˜‘‘‘“
843 � HIGH BYTE � LOW BYTE �
844 ”‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘•
845 LOCATION N + 1 LOCATION N
847 Each byte within a word has its own particular address, and the smaller of
848 the two addresses is used as the address of the word. The byte at this lower
849 address contains the eight least significant bits of the word, while the
850 byte at the higher address contains the eight most significant bits. The
851 arrangement of bytes within words is illustrated in figure 2-2.
853 Note that a word need not be aligned at an even-numbered byte address. This
854 allows maximum flexibility in data structures (e.g., records containing
855 mixed byte and word entries) and efficiency in memory utilization. Although
856 actual transfers of data between the processor and memory take place at
857 physically aligned word boundaries, the 80286 converts requests for
858 unaligned words into the appropriate sequences of requests acceptable to the
859 memory interface. Such odd aligned word transfers, however, may impact
860 performance by requiring two memory cycles to transfer the word rather than
861 one. Data structures (e.g., stacks) should therefore be designed in such a
862 way that word operands are aligned on word boundaries whenever possible for
863 maximum system performance. Due to instruction prefetching and queueing
864 within the CPU, there is no requirement for instructions to be aligned on
865 word boundaries and no performance loss if they are not.
867 Although bytes and words are the fundamental data types of operands, the
868 processor also supports additional interpretations on these bytes or words.
869 Depending on the instruction referencing the operand, the following
870 additional data types can be recognized:
873 A signed binary numeric value contained in an 8-bit byte or a 16-bit word.
874 All operations assume a 2's complement representation. (Signed 32- and
875 64-bit integers are supported using the 80287 Numeric Data Processor.)
878 An unsigned binary numeric value contained in an 8-bit byte or 16-bit word.
881 A 32-bit address quantity composed of a segment selector component and an
882 offset component. Each component is a 16-bit word.
885 A contiguous sequence of bytes or words. A string may contain from 1 byte
889 A byte representation of alphanumeric and control characters using the
890 ASCII standard of character representation.
893 A byte (unpacked) representation of the decimal digits (0-9).
896 A byte (packed) representation of two decimal digits (0-9). One digit is
897 stored in each nibble of the byte.
900 A signed 32-, 64-, or 80-bit real number representation. (Floating operands
901 are supported using the 80287 Numeric Processor Configuration.)
903 Figure 2-3 graphically represents the data types supported by the 80286.
904 80286 arithmetic operations may be performed on five types of numbers:
905 unsigned binary, signed binary (integers), unsigned packed decimal, unsigned
906 unpacked decimal, and floating point. Binary numbers may be 8 or 16 bits
907 long. Decimal numbers are stored in bytes; two digits per byte for packed
908 decimal, one digit per byte for unpacked decimal. The processor always
909 assumes that the operands specified in arithmetic instructions contain data
910 that represent valid numbers for the type of instruction being performed.
911 Invalid data may produce unpredictable results.
913 Unsigned binary numbers may be either 8 or 16 bits long; all bits are
914 considered in determining a number's magnitude. The value range of an 8-bit
915 unsigned binary number is 0-255; 16 bits can represent values from 0 through
916 65,535. Addition, subtraction, multiplication and division operations are
917 available for unsigned binary numbers.
919 Signed binary numbers (integers) may be either 8 or 16 bits long. The
920 high-order (leftmost) bit is interpreted as the number's sign: 0 = positive
921 and 1 = negative. Negative numbers are represented in standard two's
922 complement notation. Since the high-order bit is used for a sign, the range
923 of an 8-bit integer is -128 through +127; 16-bit integers may range from
924 -32,768 through +32,767. The value zero has a positive sign.
926 Separate multiplication and division operations are provided for both
927 signed and unsigned binary numbers. The same addition and subtraction
928 instructions are used with signed or unsigned binary values. Conditional
929 jump instructions, as well as an "interrupt on overflow" instruction, can
930 be used following an unsigned operation on an integer to detect overflow
933 Unpacked decimal numbers are stored as unsigned byte quantities. One digit
934 is stored in each byte. The magnitude of the number is determined from the
935 low-order half-byte; hexadecimal values 0-9 are valid and are interpreted as
936 decimal numbers. The high-order half-byte must be zero for multiplication
937 and division; it may contain any value for addition and subtraction.
939 Arithmetic on unpacked decimal numbers is performed in two steps. The
940 unsigned binary addition, subtraction and multiplication operations are used
941 to produce an intermediate result. An adjustment instruction then changes
942 the value to a final correct unpacked decimal number. Division is performed
943 similarly, except that the adjustment is carried out on the two digit
944 numerator operand in register AX first, followed by an unsigned binary
945 division instruction that produces a correct result.
947 Unpacked decimal numbers are similar to the ASCII character representations
948 of the digits 0-9. Note, however, that the high-order half-byte of an ASCII
949 numeral is always 3. Unpacked decimal arithmetic may be performed on ASCII
950 numeric characters under the following conditions:
952 Ž the high-order half-byte of an ASCII numeral must be set to 0H prior
953 to multiplication or division.
955 Ž unpacked decimal arithmetic leaves the high-order half-byte set to 0H;
956 it must be set to 3 to produce a valid ASCII numeral.
958 Packed decimal numbers are stored as unsigned byte quantities. The byte is
959 treated as having one decimal digit in each half-byte (nibble); the digit in
960 the high-order half-byte is the most significant. Values 0-9 are valid in
961 each half-byte, and the range of a packed decimal number is 0-99. Additions
962 and subtractions are performed in two steps. First, an addition or
963 subtraction instruction is used to produce an intermediate result. Then, an
964 adjustment operation is performed which changes the intermediate value to a
965 final correct packed decimal result. Multiplication and division
966 adjustments are only available for unpacked decimal numbers.
968 Pointers and addresses are described below in section 2.3.3, "Index,
969 Pointer, and Base Registers," and in section 3.8, "Address Manipulation
972 Strings are contiguous bytes or words from 1 to 64K bytes in length. They
973 generally contain ASCII or other character data representations. The 80286
974 provides string manipulation instructions to move, examine, or modify a
975 string (see section 3.7, "Character Translation and String Instructions").
977 If the 80287 numeric processor extension (NPX) is present in the system ‘‘
978 see the 80287 NPX book‘‘the 80286 architecture also supports floating point
979 numbers, 32- and 64-bit integers, and 18-digit BCD data types.
981 The 80287 Numeric Data Processor supports and stores real numbers in a
982 three-field binary format as required by IEEE standard 754 for floating
983 point numerics (see figure 2-3). The number's significant digits are held
984 in the significand field, the exponent field locates the binary point within
985 the significant digits (and therefore determines the number's magnitude),
986 and the sign field indicates whether the number is positive or negative.
987 (The exponent and significand are analogous to the terms "characteristic"
988 and "mantissa," typically used to describe floating point numbers on some
989 computers.) This format is used by the 80287 with various length
990 significands and exponents to support single precision, double precision and
991 extended (80-bit) precision floating point data types. Negative numbers
992 differ from positive numbers only in their sign bits.
995 Figure 2-1. Segmented Virtual Memory
997 ’‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ “
998 20000‚����������������ƒ 8000‚���������������ƒ
999 � €CS € � € € 8600‚���������������ƒ
1000 € MAIN € € PROCEDURE A € € PROCEDURE €
1001 � € PROCEDURE € � € € € B €
1002 0„����������������… 0„���������������… 0„���������������…
1004 ‚����������������ƒ 72535‚���������������ƒ ‚���������������ƒ
1006 € DATA (MAIN) € € DATA (A) € € DATA (B) €
1007 � 0„����������������… � 0„���������������… 0„���������������…
1008 2000‚����������������ƒ
1011 � 0„����������������… �
1013 � €ES PROCESS-WIDE € �
1015 � 0„����������������… �
1016 ”‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ •
1017 CURRENTLY ACCESSIBLE
1020 Figure 2-2. Bytes and Words in Memory
1024 All values in hexadecimal. MEMORY VALUES
1026 †�����������������������‡
1028 †�����������������������‡
1030 †�����������������������‡
1032 †�����������������������‡ –‘ WORD AT ADDRESS B CONTAINS FE06
1034 †�����������������������‡
1036 †�����������������������‡‘“
1037 9 € 1F € –‘BYTE AT ADDRESS 9 CONTAINS 1F
1038 †�����������������������‡‘•
1040 †�����������������������‡
1042 †�����������������������‡ –‘ WORD AT ADDRESS 6 CONTAINS 23OB
1044 †�����������������������‡
1046 †�����������������������‡
1048 †�����������������������‡
1050 †�����������������������‡‘“–‘ WORD AT ADDRESS 2 CONTAINS 74CB
1052 †�����������������������‡ –‘ WORD AT ADDRESS 1 CONTAINS CB31
1054 †�����������������������‡‘•
1056 „�����������������������…
1059 Figure 2-3. 80286/80287 Supported Data Types
1063 SIGNED ‚ÐÐÐÐÐÐЃ UNSIGNED ‚ÐÐÐÐÐÐЃ SIGNED ‚ÐÐÐÐÐÐÐÐÐÐÐÐÐÐЃ
1064 BYTE €� � € BYTE € � € WORD €� � � � €
1065 „¤������… „�������… „¤������¤�������…
1066 SIGN BIT•”‘‘‘‘‘‘• �”MSB � SIGN BIT•”MSB �
1067 MAGNITUDE ”‘‘‘‘‘‘‘• ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
1073 Supported by 80287 numeric data processor configuration. ‚ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐЃ
1075 „¤������¤�������¤�������¤�������…
1077 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
1080 +7 +6 +5 +4 +3 +2 +1 0
1081 63 48 47 32 31 16 15 0
1083 Supported by 80287 numeric data processor configuration. ‚Ð��Ð���Ð���Ð���Ð���Ð���Ð���Ð���ƒ
1085 „¤��¤���¤���¤���¤���¤���¤���¤���…
1087 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
1092 UNSIGNED WORD ‚ÐÐÐÐÐÐÐÐÐÐÐÐÐÐЃ
1101 BINARY CODED DECIMAL ‚ÐÐÐÐÐÐЃ ‚ÐÐÐÐÐÐÐÐÐÐÐÐÐÐЃ
1102 (BCD) € � €
\a\a\a € � � � €
1103 „�������… „�������¤�������…
1105 DIGIT N DIGIT 1 DIGIT 0
1109 ASCII ‚ÐÐÐÐÐÐЃ ‚ÐÐÐÐÐÐÐÐÐÐÐÐÐÐЃ
1110 € � €
\a\a\a € � � � €
1111 „�������… „�������¤�������…
1113 CHARACTER[N] CHARACTER{1} CHARACTER{0}
1117 PACKED BCD ‚ÐÐÐÐÐÐЃ ‚ÐÐÐÐÐÐÐÐÐÐÐÐÐÐЃ
1118 € � €
\a\a\a € � � � €
1119 „�������… „�������¤�������…
1122 SIGNIFICANT SIGNIFICANT
1126 7/15 0 7/15 0 7/15 0
1127 STRING ‚ÐÐÐÐÐÐЃ ‚ÐÐÐÐÐÐÐÐÐÐÐÐÐÐЃ
1128 € � €
\a\a\a € � � � €
1129 „�������… „�������¤�������…
1130 BYTE/WORD N BYTE/WORD BYTE/WORD
1135 POINTER ‚ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐЃ
1137 „¤������¤�������¤�������¤�������…
1138 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
1141 +9 +8 +7 +6 +5 +4 +3 +2 +1 0
1144 Supported by 80287 numeric data processor configuration. ‚Ð��Ð���Ð���Ð���Ð���Ð���Ð���Ð���Ð���Ð���ƒ
1145 €� � � � � � � � � � €
1146 „¤��¤���¤���¤���¤���¤���¤���¤���¤���¤���…
1147 SIGN BIT•”‘‘‘‘‘‘‘‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
1153 The 80286 contains a total of fourteen registers that are of interest to
1154 the application programmer. (Five additional registers used by system
1155 programmers are covered in section 10.1.) As shown in figure 2-4, these
1156 registers may be grouped into four basic categories:
1158 Ž General registers. These eight 16-bit general-purpose registers are
1159 used primarily to contain operands for arithmetic and logical
1162 Ž Segment registers. These four special-purpose registers determine, at
1163 any given time, which segments of memory are currently addressable.
1165 Ž Status and Control registers. These three special-purpose registers
1166 are used to record and alter certain aspects of the 80286 processor
1170 2.3.1 General Registers
1172 The general registers of the 80286 are the 16-bit registers AX, BX, CX, DX,
1173 SP, BP, SI, and DI. These registers are used interchangeably to contain the
1174 operands of logical and arithmetic operations.
1176 Some instructions and addressing modes (see section 2.4), however, dedicate
1177 certain general registers to specific uses. BX and BP are often used to
1178 contain the base address of data structures in memory (for example, the
1179 starting address of an array); for this reason, they are often referred to
1180 as the base registers. Similarly, SI and DI are often used to contain an
1181 index value that will be incremented to step through a data structure; these
1182 two registers are called the index registers. Finally, SP and BP are used
1183 for stack manipulation. Both SP and BP normally contain offsets into the
1184 current stack. SP generally contains the offset of the top of the stack and
1185 BP contains the offset or base address of the current stack frame. The use
1186 of these general-purpose registers for operand addressing is discussed in
1187 section 2.3.3, "Index, Pointer, and Base Registers." Register usage for
1188 individual instructions is discussed in chapters 3 and 4.
1190 As shown in figure 2-4, eight byte registers overlap four of the 16-bit
1191 general registers. These registers are named AH, BH, CH, and DH (high
1192 bytes); and AL, BL, CL, and DL (low bytes); they overlap AX, BX, CX, and DX.
1193 These registers can be used either in their entirety or as individual 8-bit
1194 registers. This dual interpretation simplifies the handling of both 8- and
1195 16-bit data elements.
1198 Figure 2-4. 80286 Base Architecture Register Set
1203 GENERAL REGISTERS 7 0 7 0
1204 ’‘ ‚������Ð������ƒ‘“
1206 BYTE � Ñ‘‘‘‘‘š‘‘‘‘‘‘ –‘MULTIPLY/DIVIDE
1207 ADDRESSABLE � DX € DH � DL € � I/O INSTRUCTIONS
1208 (8-BIT‘— Ñ‘‘‘‘‘š‘‘‘‘‘‘Â�Á
1209 REGISTER � CX € CH � CL € –‘LOOP/SHIFT/REPEAT COUNT
1210 NAMES � Ñ‘‘‘‘‘š‘‘‘‘‘‘Â�Á
1211 SHOWN) � BX € BH � BL € �
1212 ”‘ Ñ‘‘‘‘‘™‘‘‘‘‘‘ –‘BASE REGISTERS
1216 Ñ‘‘‘‘‘‘‘‘‘‘‘‘ –‘INDEX REGISTERS
1219 SP € € –‘STACK POINTER
1223 SEGMENT REGISTERS 15 0
1225 CS € € CODE SEGMENT SELECTOR
1227 DS € € DATA SEGMENT SELECTOR
1229 SS € € STACK SEGMENT SELECTOR
1231 ES € € EXTRA SEGMENT SELECTOR
1234 STATUS AND CONTROL 15 0
1235 REGISTERS ‚�������������ƒ
1238 IP € € INSTRUCTION POINTER
1240 MSW € € MACHINE STATUS WORD
1244 2.3.2 Memory Segmentation and Segment Registers
1246 Complete programs generally consist of many different code modules (or
1247 segments), and different types of data segments. However, at any given time
1248 during program execution, only a small subset of a program's segments are
1249 actually in use. Generally, this subset will include code, data, and
1250 possibly a stack. The 80286 architecture takes advantage of this by
1251 providing mechanisms to support direct access to the working set of a
1252 program's execution environment and access to additional segments on
1255 At any given instant, four segments of memory are immediately accessible to
1256 an executing 80286 program. The segment registers DS, ES, SS, and CS are
1257 used to identify these four current segments. Each of these registers
1258 specifies a particular kind of segment, as characterized by the associated
1259 mnemonics ("code," "stack," "data," or "extra") shown in figure 2-4.
1261 An executing program is provided with concurrent access to the four
1262 individual segments of memory‘‘a code segment, a stack segment, and two
1263 data segments‘‘by means of the four segment registers. Each may be said to
1264 select a segment, since it uniquely determines the one particular segment
1265 from among the numerous segments in memory, which is to be immediately
1266 accessible at highest speed. Thus, the 16-bit contents of a segment register
1267 is called a segment selector.
1269 Once a segment is selected, a base address is associated with it. To
1270 address an element within a segment, a 16-bit offset from the segment's base
1271 address must be supplied. The 16-bit segment selector and the 16-bit offset
1272 taken together form the high and low order halves, respectively, of a
1273 32-bit virtual address pointer. Once a segment is selected, only the lower
1274 16-bits of the pointer, called the offset, generally need to be specified by
1275 an instruction. Simple rules define which segment register is used to form
1276 an address when only a 16-bit offset is specified.
1278 An executing program requires, first of all, that its instructions reside
1279 somewhere in memory. The segment of memory containing the currently
1280 executing sequence of instructions is known as the current code segment; it
1281 is specified by means of the CS register. All instructions are fetched from
1282 this code segment, using as an offset the contents of the instruction
1283 pointer (IP). The CS:IP register combination therefore forms the full 32-bit
1284 pointer for the next sequential program instruction. The CS register is
1285 manipulated indirectly. Transitions from one code segment to another (e.g.,
1286 a procedure call) are effected implicitly as the result of control-transfer
1287 instructions, interrupts, and trap operations.
1289 Stacks play a fundamental role in the 80286 architecture; subroutine calls,
1290 for example, involve a number of implicit stack operations. Thus, an
1291 executing program will generally require a region of memory for its stack.
1292 The segment containing this region is known as the current stack segment,
1293 and it is specified by means of the SS register. All stack operations are
1294 performed within this segment, usually in terms of address offsets contained
1295 in the stack pointer (SP) and stack frame base (BP) registers. Unlike CS,
1296 the SS register can be loaded explicitly for dynamic stack definition.
1298 Beyond their code and stack requirements, most programs must also fetch and
1299 store data in memory. The DS and ES registers allow the specification of two
1300 data segments, each addressable by the currently executing program.
1301 Accessibility to two separate data areas supports differentiation and
1302 access requirements like local procedure data and global process data. An
1303 operand within a data segment is addressed by specifying its offset either
1304 directly in an instruction or indirectly via index and/or base registers
1305 (described in the next subsection).
1307 Depending on the data structure (e.g., the way data is parceled into one or
1308 more segments), a program may require access to multiple data segments. To
1309 access additional segments, the DS and ES registers can be loaded under
1310 program control during the course of a program's execution. This simply
1311 requires loading the appropriate data pointer prior to accessing the data.
1313 The interpretation of segment selector values depends on the operating mode
1314 of the processor. In Real Address Mode, a segment selector is a physical
1315 address (figure 2-5). In Protected Mode, a segment selector selects a
1316 segment of the user's virtual address space (figure 2-6). An intervening
1317 level of logical-to-physical address translation converts the logical
1318 address to a physical memory address. Chapter 6, "Memory Management,"
1319 provides a detailed discussion of Protected Mode addressing. In general,
1320 considerations of selector formats and the details of memory mapping need
1321 not concern the application programmer.
1324 2.3.3 Index, Pointer, and Base Registers
1326 Five of the general-purpose registers are available for offset address
1327 calculations. These five registers, shown in figure 2-4, are SP, BP, BX,
1328 SI, and DI. SP is called a pointer register; BP and BX are called base
1329 registers; SI and DI are called index registers.
1331 As described in the previous section, segment registers define the set of
1332 four segments currently addressable by a program. A pointer, base, or index
1333 register may contain an offset value relative to the start of one of these
1334 segments; it thereby points to a particular operand's location within that
1335 segment. To allow for efficient computations of effective address offsets,
1336 all base and index registers may participate interchangeably as operands in
1337 most arithmetical operations.
1339 Stack operations are facilitated by the stack pointer (SP) and stack frame
1340 base (BP) registers. By specifying offsets into the current stack segment,
1341 each of these registers provides access to data on the stack. The SP
1342 register is the customary top-of-stack pointer, addressing the uppermost
1343 datum on a push-down stack. It is referenced implicitly by PUSH and POP
1344 operations, subroutine calls, and interrupt operations. The BP register
1345 provides yet another offset into the stack segment. The existence of this
1346 stack relative base register, in conjunction with certain addressing modes
1347 described in section 2.4.3, is particularly useful for accessing data
1348 structures, variables and dynamically allocated work space within the stack.
1350 Stacks in the 80286 are implemented in memory and are located by the stack
1351 segment register (SS) and the stack pointer register (SP). A system may have
1352 an unlimited number of stacks, and a stack may be up to 64K bytes long, the
1353 maximum length of a segment.
1355 One stack is directly addressable at a time; this is the current stack,
1356 often referred to simply as "the" stack. SP contains the current top of the
1357 stack (TOS). In other words, SP contains the offset to the top of the push
1358 down stack from the stack segment's base address. Note, however, that the
1359 stack's base address (contained in SS) is not the "bottom" of the stack
1362 80286 stack entries are 16 bits wide. Instructions operate on the stack by
1363 adding and removing stack items one word at a time. An item is pushed onto
1364 the stack (see figure 2-8) by decrementing SP by 2 and writing the item at
1365 the new TOS. An item is popped off the stack by copying it from TOS and then
1366 incrementing SP by 2. In other words, the stack grows down in memory toward
1367 its base address. Stack operations never move items on the stack; nor do
1368 they erase them. The top of the stack changes only as a result of updating
1371 The stack frame base pointer (BP) is often used to access elements on the
1372 stack relative to a fixed point on the stack rather than relative to the
1373 current TOS. It typically identifies the base address of the current
1374 stack frame established for the current procedure (figure 2-9). If an index
1375 register is used relative to BP (e.g., base + index addressing mode using BP
1376 as the base), the offset will be calculated automatically in the current
1379 Accessing data structures in data segments is facilitated by the BX
1380 register, which has the same function in addressing operands within data
1381 segments that BP does for stack segments. They are called base registers
1382 because they may contain an offset to the base of a data structure. The
1383 similar usage of these two registers is especially important when discussing
1384 addressing modes (see section 2.4, "Addressing Modes").
1386 Operations on data are also facilitated by the SI and DI registers. By
1387 specifying an offset relative to the start of the currently addressable data
1388 segment, an index register can be used to address an operand in the segment.
1389 If an index register is used in conjunction with the BX base register
1390 (i.e., base + index addressing) to form an offset address, the data is also
1391 assumed to reside in the current data segment. As a rule, data referenced
1392 through an index register or BX is presumed to reside in the current data
1393 segment. That is, if an instruction invokes addressing for one of its
1394 operands using either BX, DI, SI, or BX with SI or DI, the contents of the
1395 register(s) (BX, DI, or SI) implicitly specify an offset in the current data
1396 segment. As previously mentioned, data referenced via SP, BP or BP with SI
1397 or DI implicitly specify an operand in the current stack segment (refer to
1400 There are two exceptions to the rules listed above. The first concerns the
1401 operation of certain 80286 string instructions. For the most flexibility,
1402 these instructions assume that the DI register addresses destination strings
1403 not in the data segment, but rather in the extra segment (ES register).
1404 This allows movement of strings between different segments. This has led to
1405 the descriptive names "source index" and "destination index." In all cases
1406 other than string instructions, however, the SI and DI registers may be used
1407 interchangeably to reference either source or destination operands.
1409 A second more general override capability allows the programmer complete
1410 control of which segment is used for a specific operation. Segment-override
1411 prefixes, discussed in section 2.4.3, allow the index and base registers to
1412 address data in any of the four currently addressable segments.
1415 Table 2-1. Implied Segment Usage by Index, Pointer, and Base Registers
1417 Register Implied Segment
1421 DI DS, ES for String Operations
1425 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
1427 All implied Segment usage, except SP to SS and DI to ES for String
1428 Operations, may be explicitly specified with a segment override prefix for
1429 any of the four segments. The prefix precedes the instruction for which
1430 explicit reference is desired.
1431 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
1434 Figure 2-5. Real Address Mode Segment Selector Interpretation
1439 ’‘†���������������‡ � 1 MEGABYTE
1440 SEGMENT 64K BYTES ‘— € SEG 1 € –‘ PHYSICAL
1441 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10”‘†���������������‡ � ADDRESS
1442 � BASE ADDRESS € € � SPACE
1444 ‚�����¤������Ð������ƒ € € �
1445 € SELECTOR � 0000 € „���������������…‘•
1446 „������������¤������…
1448 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
1450 1. The selector inentifies a segment in physical memory.
1451 2. A selector specifies the segments base address, Modulo 16, within
1452 the 1 Megabyte address space.
1453 3. The selector is the 16 most significant bits of a segments physical
1455 4. The values of selectors determines the amount they overlap in real
1457 5. Segments may overlap by increments of 16 bytes. Overlap ranges from
1458 complete (SEG 1 = SEG 1) to none (SEG 1 Ï SEG 2 ± 64K).
1459 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
1462 Figure 2-6. Protected Mode Segment Selector Interpretation
1468 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10†������������‡ �
1469 ‚�������¤������ƒ € SEG 3FFD € �
1470 € SELECTOR € ’‘†������������‡ �
1471 „��������������… 1 TO 64K BYTES‘— € SEG 3FFC € �
1474 †������������‡ � 1 GIGABYTE
1476 †������������‡ � ADDRESS
1488 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
1490 1. A selector uniquely identifies (names) one of 16K possible segments
1491 in the task's virtual address space.
1492 2. The selector value does not specify the segment's location in
1494 3. The selector does not imply any overlap with other segments (This
1495 depends on the base address of the segment via the memory management
1496 and protection information).
1497 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
1500 Figure 2-7. 80286 Stack
1502 ‚�����������������ƒ LOGICAL
1503 € €
\x11‘‘‘ BOTTOM OF STACK
1504 †�����������������‡ (initial SP value)
1510 †�����������������‡ �
1511 ’‘‘‘‘‘‘‘‘‘‘‘
\x10€ €
\x11‘‘‘ LOGICAL TOP OF STACK
1512 � †�����������������‡ �
1513 � € €
\x1f PUSH-DOWN
1520 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10„�����������������… STACK SEGMENT BASE ADDRESS
1523 Figure 2-8. Stack Operation
1525 STACK OPERATION FOR CODE SEQUENCE:
1528 POP BX ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
\a \a \x1e
1529 �EXISTING STACK� Ñ‘‘‘‘‘‘‘‘ � BOTTOM
1530 � BEFORE PUSH � 1062 € 0 0 0 0 € � OF
1531 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘• Ñ‘‘‘‘‘‘‘‘ � STACK
1540 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10 1058 € 5 5 5 5 €
1541 SS � SP Ñ‘‘‘‘‘‘‘‘‘“
1542 ‚����������Ð�����¤����ƒ 1056 € 6 6 6 6 € �
1543 € SELECTOR � OFFSET € Ñ‘‘‘‘‘‘‘‘ � NOT
1544 „����Ð�����¤����������… 1054 € 7 7 7 7 € –‘ PRESENTLY
1545 � Ñ‘‘‘‘‘‘‘‘ � USED
1546 � 1052 € 8 8 8 8 € �
1550 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10 0000 Ñ‘‘‘‘‘‘‘‘Â
1565 105A € 4 4 4 4 € PUSH AX
1566 Ñ‘‘‘‘‘‘‘‘‚���������ƒ
1567 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10 1058 € 5 5 5 5 €€ A A A A €
1568 SS � SP Ñ‘‘‘‘‘‘‘‘„��Ð������…
1569 ‚����������Ð�����¤����ƒ 1056 € A A A A €
\x11‘‘•
1570 € SELECTOR � OFFSET € Ñ‘‘‘‘‘‘‘‘Â
1571 „����Ð�����¤����������… 1054 € 7 7 7 7 €
1577 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10 0000 Ñ‘‘‘‘‘‘‘‘Â
1590 105C € 3 3 3 3 € ‚���������ƒ
1591 Ñ‘‘‘‘‘‘‘‘ € 5 5 5 5 €
1592 105A € 4 4 4 4 € „���������…
1594 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10 1058 € 5 5 5 5 €‘‘‘‘‘‘•
1596 ‚����������Ð�����¤����ƒ 1056 € A A A A €‘‘‘‘‘‘“
1597 € SELECTOR � OFFSET € Ñ‘‘‘‘‘‘‘‘Â
\x1f
1598 „����Ð�����¤����������… 1054 € 7 7 7 7 € ‚���������ƒ
1599 � Ñ‘‘‘‘‘‘‘‘ € A A A A €
1600 � 1052 € 8 8 8 8 € „���������…
1601 � Ñ‘‘‘‘‘‘‘‘ POP AX
1604 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10 0000 Ñ‘‘‘‘‘‘‘‘Â
1608 Figure 2-9. BP Usage as a Stack Frame Base Pointer
1610 BP is a constant pointer to stack based variables and work space. All
1611 references use BP and are independent of SP, which may vary during a routine
1617 CALL PROC_N 1 ‘‘‘‘‘‘‘‘‘
\x10 PROC_N+1
1618 \x11‘‘‘‘‘‘‘“ PUSH BP
1621 � SUB SP, WORK_SPACE
1639 Ñ‘‘‘‘‘‘‘‘‘‘‘‘ –‘PROCEDURE N
1640 ‚ � �ƒ € REGISTERS € � STACK FRAME
1641 BP ‘‘‘‘‘‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘ �
1642 „� � … € € � PROCEDURE
1643 \x1e € WORK_SPACE € � N+1 STACK
1644 BOTTOM � Ñ‘‘‘‘‘‘‘‘‘‘‘‘Â�Á FRAME
1645 OF � € PARAMETERS € –‘‘‘‘‘‘•
1646 STACK � Ñ‘‘‘‘‘‘‘‘‘‘‘‘ � DYNAMICALLY
1647 € RETURN ADDR € � ALLOCATED
1648 Ñ‘‘‘‘‘‘‘‘‘‘‘‘ � ON DEMAND
1649 ‚����ƒ € REGISTERS € � RATHER THAN
1650 € BP Ñ‘‘‘‘‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘ �“STATICALLY
1653 ’‘ ‘‘ ‘‘ ‘‘ ‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘••
\x11‘‘‘“
1654 –‘ ‘‘ ‘‘ ‘‘ ‘
\x10€ € TOP OF STACK
1656 € SS � SP € „�������������… STACK SEGMENT BASE
1660 2.3.4 Status and Control Registers
1662 Two status and control registers are of immediate concern to applications
1663 programmers: the instruction pointer and the FLAGS registers.
1665 The instruction pointer register (IP) contains the offset address, relative
1666 to the start of the current code segment, of the next sequential instruction
1667 to be executed. Together, the CS:IP registers thus define a 32-bit
1668 program-counter. The instruction pointer is not directly visible to the
1669 programmer; it is controlled implicitly, by interrupts, traps, and
1670 control-transfer operations.
1672 The FLAGS register encompasses eleven flag fields, mostly one-bit wide, as
1673 shown in figure 2-10. Six of the flags are status flags that record
1674 processor status information. The status flags are affected by the execution
1675 of arithmetic and logical instructions. The carry flag is also modifiable
1676 with instructions that will clear, set or complement this flag bit. See
1679 The carry flag (CF) generally indicates a carry or borrow out of the most
1680 significant bit of an 8- or 16-bit operand after performing an arithmetic
1681 operation; this flag is also useful for bit manipulation operations
1682 involving the shift and rotate instructions. The effect on the remaining
1683 status flags, when defined for a particular instruction, is generally as
1684 follows: the zero flag (ZF) indicates a zero result when set; the sign flag
1685 (SF) indicates whether the result was negative (SF=1) or positive (SF=0);
1686 when set, the overflow flag (OF) indicates whether an operation results in
1687 a carry into the high order bit of the result but not a carry out of the
1688 high-order bit, or vice versa; the parity flag (PF) indicates whether the
1689 modulo 2 sum of the low-order eight bits of the operation is even (PF=0) or
1690 odd (PF=1) parity. The auxiliary carry flag (AF) represents a carry out of
1691 or borrow into the least significant 4-bit digit when performing binary
1692 coded decimal (BCD) arithmetic.
1694 The FLAGS register also contains three control flags that are used, under
1695 program control, to direct certain processor operations. The
1696 interrupt-enable flag (IF), if set, enables external interrupts; otherwise,
1697 interrupts are disabled. The trap flag (TF), if set, puts the processor
1698 into a single-step mode for debugging purposes where the target program is
1699 automatically interrupted to a user supplied debug routine after the
1700 execution of each target program instruction. The direction flag (DF)
1701 controls the forward or backward direction of string operations: 0 = forward
1702 or auto increment the address register(s) (SI, DI or SI and DI),
1703 1 = backward or auto-decrement the address register(s) (SI, DI or SI
1706 In general, the interrupt enable flag may be set or reset with special
1707 instructions (STI = set, CLI = clear) or by placing the flags on the stack,
1708 modifying the stack, and returning the flag image from the stack to the flag
1709 register. If operating in Protected Mode, the ability to alter the IF bit
1710 is subject to protection checks to prevent non-privileged programs from
1711 effecting the interrupt state of the CPU. This applies to both instruction
1712 and stack options for modifying the IF bit.
1714 The TF flag may only be modified by copying the flag register to the stack,
1715 setting the TF bit in the stack image, and returning the modified stack
1716 image to the flag register. The trap interrupt occurs on completion of the
1717 next instruction. Entry to the single step routine saves the flag register
1718 on the stack with the TF bit set, and resets the TF bit in the register.
1719 After completion of the single step routine, the TF bit is automatically set
1720 on return to the program being single stepped to interrupt the program again
1721 after completion of the next instruction. Use of TF is not inhibited by the
1722 protection mechanism in Protected Mode.
1724 The DF flag, like the IF flag, is controlled by instructions (CLD = clear,
1725 STD = set) or flag register modification through the stack. Typically,
1726 routines that use string instructions will save the flags on the stack,
1727 modify DF as necessary via the instructions provided, and restore DF to its
1728 original state by restoring the Flag register from the stack before
1729 returning. Access or control of the DF flag is not inhibited by the
1730 protection mechanism in Protected Mode.
1732 The Special Fields bits are only relevant in Protected Mode. Real Address
1733 Mode programs should treat these bits as don't-care's, making no assumption
1734 about their status. Attempts to modify the IOPL and NT fields are subject to
1735 protection checking in Protected Mode. In general, the application's
1736 programmer will not be able to and should not attempt to modify these bits.
1737 (See section 10.3, "Privileged and Trusted Instructions" for more details.)
1740 Figure 2-10. Flags Register
1743 CARRY‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
1744 PARITY‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“ �
1745 AUXILLIARY CARRY‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“ � �
1746 ZERO‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“ � � �
1747 SIGN‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“ � � � �
1748 OVERFLOW‘‘‘‘‘‘‘‘‘‘‘‘“ � � � � �
1750 15 14 13 12
\x1f11 10 9 8
\x1f 7
\x1f 6 5
\x1f 4 3
\x1f 2 1
\x1f 0
1751 ‚��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��ƒ
1752 FLAGS:€œœ�NT�IOPL �OF�DF�IF�TF�SF�ZF�œœ�AF�œœ�PF�œœ�CF€
1753 „��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��…
1754 \x1e \x1e \x1e \x1e \x1e
1755 � � � � � CONTROL FLAGS:
1756 � � � � ”‘‘‘‘‘‘‘‘‘‘‘TRAP FLAG
1757 � � � ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘INTERRUPT ENABLE
1758 � � ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘DIRECTION FLAG
1760 � ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘I/O PRIVILEGE LEVEL
1761 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘NESTED TASK FLAG
1764 2.4 Addressing Modes
1766 The information encoded in an 80286 instruction includes a specification of
1767 the operation to be performed, the type of the operands to be manipulated,
1768 and the location of these operands. If an operand is located in memory, the
1769 instruction must also select, explicitly or implicitly, which of the
1770 currently addressable segments contains the operand. This section covers the
1771 operand addressing mechanisms; 80286 operators are discussed in Chapter 3.
1773 The five elements of a general instruction are briefly described below. The
1774 exact format of 80286 instructions is specified in Appendix B.
1776 Ž The opcode is present in all instructions; in fact, it is the only
1777 required element. Its principal function is the specification of the
1778 operation performed by the instruction.
1780 Ž A register specifier.
1782 Ž The addressing mode specifier, when present, is used to specify the
1783 addressing mode of an operand for referencing data or performing
1784 indirect calls or jumps.
1786 Ž The displacement, when present, is used to compute the effective
1787 address of an operand in memory.
1789 Ž The immediate operand, when present, directly specifies one operand of
1792 Of the four elements, only one, the opcode, is always present. The other
1793 elements may or may not be present, depending on the particular operation
1794 involved and on the location and type of the operands.
1799 Generally speaking, an instruction is an operation performed on zero, one,
1800 or two operands, which are the data manipulated by the instruction. An
1801 operand can be located either in a register (AX, BX, CX, DX, SI, DI, SP, or
1802 BP in the case of 16-bit operands; AH, AL, BH, BL, CH, CL, DH, or DL in the
1803 case of 8-bit operands; the FLAG register for flag operations in the
1804 instruction itself (as an immediate operand)), or in memory or an I/O port.
1805 Immediate operands and operands in registers can be accessed more rapidly
1806 than operands in memory since memory operands must be fetched from memory
1807 while immediate and register operands are available in the processor.
1809 An 80286 instruction can reference zero, one, or two operands. The three
1810 forms are as follows:
1812 Ž Zero-operand instructions, such as RET, NOP, and HLT. Consult Appendix
1815 Ž One-operand instructions, such as INC or DEC. The location of the
1816 single operand can be specified implicitly, as in AAM (where the
1817 register AX contains the operand), or explicitly, as in INC (where
1818 the operand can be in any register or memory location). Explicitly
1819 specified operands are accessed via one of the addressing modes
1820 described in section 2.4.2.
1822 Ž Two operand instructions such as MOV, ADD, XOR, etc., generally
1823 overwrite one of the two participating operands with the result. A
1824 distinction can thus be made between the source operand (the one left
1825 unaffected by the operation) and the destination operand (the one
1826 overwritten by the result). Like one-operand instructions, two-operand
1827 instructions can specify the location of operands either explicitly or
1828 implicitly. If an instruction contains two explicitly specified
1829 operands, only one of them‘‘either the source or the destination‘‘can
1830 be in a register or memory location. The other operand must be in a
1831 register or be an immediate source operand. Special cases of
1832 two-operand instructions are the string instructions and stack
1833 manipulation. Both operands of some string instructions are in memory
1834 and are explicitly specified. Push and pop stack operations allow
1835 transfer between memory operands and the memory based stack.
1837 Thus, the two-operand instructions of the 80286 permit operations of the
1840 Ž Register-to-register
1841 Ž Register-to-memory
1842 Ž Memory-to-register
1843 Ž Immediate-to-register
1844 Ž Immediate-to-memory
1847 Instructions can specify the location of their operands by means of eight
1848 addressing modes, which are described in sections 2.4.2 and 2.4.3.
1851 2.4.2 Register and Immediate Modes
1853 Two addressing modes are used to reference operands contained in registers
1856 Ž Register Operand Mode. The operand is located in one of the 16-bit
1857 registers (AX, BX, CX, DX, SI, DI, SP, or BP) or in one of the 8-bit
1858 general registers (AH, BH, CH, DH, AL, BL, CL, or DL).
1860 Special instructions are also included for referencing the CS, DS, ES, SS,
1861 and Flag registers as operands also.
1863 Ž Immediate Operand Mode. The operand is part of the instruction itself
1864 (the immediate operand element).
1867 2.4.3 Memory Addressing Modes
1869 Six modes are used to access operands in memory. Memory operands are
1870 accessed by means of a pointer consisting of a segment selector (see section
1871 2.3.2) and an offset, which specifies the operand's displacement in bytes
1872 from the beginning of the segment in which it resides. Both the segment
1873 selector component and the offset component are 16-bit values. (See section
1874 2.1 for a discussion of segmentation.) Only some instructions use a full
1877 Most memory references do not require the instruction to specify a full
1878 32-bit pointer address. Operands that are located within one of the
1879 currently addressable segments, as determined by the four segment registers
1880 (see section 2.3.2, "Segment Registers"), can be referenced very
1881 efficiently simply by means of the 16-bit offset. This form of address is
1882 called by short address. The choice of segment (CS, DS, ES, or SS) is either
1883 implicit within the instruction itself or explicitly specified by means of
1884 a segment override prefix (see below).
1886 See figure 2-11 for a diagram of the addressing process.
1889 2.4.3.1 Segment Selection
1891 All instructions that address operands in memory must specify the segment
1892 and the offset. For speed and compact instruction encoding, segment
1893 selectors are usually stored in the high speed segment registers. An
1894 instruction need specify only the desired segment register and an offset in
1895 order to address a memory operand.
1897 Most instructions need not explicitly specify which segment register is
1898 used. The correct segment register is automatically chosen according to the
1899 rules of table 2-1 and table 2-2. These rules follow the way programs are
1900 written (see figure 2-12) as independent modules that require areas for
1901 code and data, a stack, and access to external data areas.
1903 There is a close connection between the type of memory reference and the
1904 segment in which that operand resides (see the next section for a
1905 discussion of how memory addressing mode calculations are performed). As a
1906 rule, a memory reference implies the current data segment (i.e., the
1907 implicit segment selector is in DS) unless the BP register is involved in
1908 the address specification, in which case the current stack segment is
1909 implied (i.e, SS contains the selector).
1911 The 80286 instruction set defines special instruction prefix elements (see
1912 Appendix B). One of these is SEG, the segment-override prefix.
1913 Segment-override prefixes allow an explicit segment selection. Only in two
1914 special cases‘‘namely, the use of DI to reference destination strings in
1915 the ES segment, and the use of SP to reference stack locations in the SS
1916 segment‘‘is there an implied segment selection which cannot be overridden.
1917 The format of segment override prefixes is shown in Appendix B.
1920 Table 2-2 Segment Register Selection Rules
1922 Memory Reference Segment Register Implicit Segment
1923 Needed Used Selection Rule
1925 Instructions Code (CS) Automatic with
1926 instruction prefetch.
1928 Stack Stack (SS) All stack pushes and
1929 pops. Any memory reference
1930 which uses BP as a base
1933 Local Data Data (DS) All data references
1934 except when relative to
1935 stack or string destination.
1937 External (Global) Extra (ES) Alternate data segment
1938 Data and destination of string
1942 Figure 2-11. Two-Component Address
1946 ’‘‘‘‘‘‘‘‘‘‘‘™‘‘‘‘‘‘‘‘‘‘‘“ †�������������‡‘“
1947 ‚�����������Ð�����������ƒ € € �
1948 € SEGMENT � OFFSET € € € �
1949 „�����������¤�����������… € € �
1950 31 16 15 0 Ñ‘‘‘‘‘‘‘‘‘‘‘‘ �
1951 ”‘‘‘‘˜‘‘‘‘• ”‘‘‘‘˜‘‘‘‘• € OPERAND € � SELECTED
1952 � � € SELECTED € –‘ SEGMENT
1953 � ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘ �
1958 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10†�������������‡‘•
1963 2.4.3.2 Offset Computation
1965 The offset within the desired segment is calculated in accordance with the
1966 desired addressing mode. The offset is calculated by taking the sum of up to
1969 Ž the displacement element in the instruction
1970 Ž the base (contents of BX or BP‘‘a base register)
1971 Ž the index (contents of SI or DI‘‘an index register)
1973 Each of the three components of an offset may be either a positive or
1974 negative value. Offsets are calculated modulo 2^(16).
1976 The six memory addressing modes are generated using various combinations of
1977 these three components. The six modes are used for accessing different types
1978 of data stored in memory:
1980 addressing mode offset calculation
1981 direct address displacement alone
1982 register indirect base or index alone
1983 based base + displacement
1984 indexed index + displacement
1985 based indexed base + index
1986 based indexed with displacement base + index + disp
1988 In all six modes, the operand is located at the specified offset within the
1989 selected segment. All displacements, except direct address mode, are
1990 optionally 8- or 16-bit values. 8-bit displacements are automatically
1991 sign-extended to 16 bits. The six addressing modes are described and
1992 demonstrated in the following section on memory addressing modes.
1995 Figure 2-12. Use of Memory Segmentation
2004 ’‘‘‘‘‘‘‘‘‘‘‘“ ‚������ƒ
2005 � ‚�������ƒ � € CODE €
2006 � € CODE Ñš‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10Ñ‘‘‘‘‘ MODULE B
2007 � Ñ‘‘‘‘‘‘ � € DATA €
2008 � € DATA Ñš‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10„������…
2010 � € STACK Ñš‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“ ‚������ƒ
2011 � Ñ‘‘‘‘‘‘ � � € € PROCESS STACK
2012 � € EXTRA Ñš‘‘‘‘‘‘‘‘‘‘‘“ ”‘‘‘‘‘‘‘‘‘
\x10„������…
2014 � SEGMENT � � ‚������ƒ PROCESS
2015 � REGISTERS � � € € DATA
2016 ”‘‘‘‘‘‘‘‘‘‘‘• ”‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10„������… BLOCK 1
2027 Two modes are used for simple scalar operands located in memory:
2029 Ž Direct Address Mode. The offset of the operand is contained in the
2030 instruction as the displacement element. The offset is a 16-bit
2033 Ž Register Indirect Mode. The offset of the operand is in one of the
2034 registers SI, DI, or BX. (BP is excluded; if BP is used as a stack
2035 frame base, it requires an index or displacement component to reference
2036 either parameters passed on the stack or temporary variables allocated
2037 on the stack. The instruction level bit encoding for the BP only
2038 address mode is used to specify Direct Address mode.)
2040 The following four modes are used for accessing complex data structures in
2041 memory (see figure 2-13):
2043 Ž Based Mode. The operand is located within the selected segment at an
2044 offset computed as the sum of the displacement and the contents of a
2045 base register (BX or BP). Based mode is often used to access the same
2046 field in different copies of a structure (often called a record). The
2047 base register points to the base of the structure (hence the term
2048 "base" register), and the displacement selects a particular field.
2049 Corresponding fields within a collection of structures can be accessed
2050 simply by changing the base register. (See figure 2-13, example 1.)
2052 Ž Indexed Mode. The operand is located within the selected segment at an
2053 offset computed as the sum of the displacement and the contents of an
2054 index register (SI or DI). Indexed mode is often used to access
2055 elements in a static array (e.g., an array whose starting location is
2056 fixed at translation time). The displacement locates the beginning of
2057 the array, and the value of the index register selects one element.
2058 Since all array elements are the same length, simple arithmetic on the
2059 index register will select any element. (See figure 2-13, example 2.)
2061 Ž Based Indexed Mode. The operand is located within the selected segment
2062 at an offset computed as the sum of the base register's contents and an
2063 index register's contents. Based Indexed mode is often used to access
2064 elements of a dynamic array (i.e., an array whose base address can
2065 change during execution). The base register points to the base of the
2066 array, and the value of the index register is used to select one
2067 element. (See figure 2-13, example 3.)
2069 Ž Based Indexed Mode with Displacement. The operand is located with the
2070 selected segment at an offset computed as the sum of a base register's
2071 contents, an index register's contents, and the displacement. This mode
2072 is often used to access elements of an array within a structure. For
2073 example, the structure could be an activation record (i.e., a region
2074 of the stack containing the register contents, parameters, and
2075 variables associated with one instance of a procedure); and one
2076 variable could be an array. The base register points to the start of
2077 the activation record, the displacement expresses the distance from the
2078 start of the record to the beginning of the array variable, and the
2079 index register selects a particular element of the array. (See figure
2082 Table 2-3 gives a summary of all memory operand addressing options.
2085 Table 2-3. Memory Operand Addressing Modes
2087 Addressing Mode Offset Calculation
2089 Direct 16-bit Displacement in the instruction
2090 Register Indirect BX, SI, DI
2091 Based (BX or BP) + Displacement
2092 The displacement can be a 0, 8 or 16-bit value.
2093 Indexed (SI or DI) + Displacement
2094 The displacement can be a 0, 8 or 16-bit value.
2095 Based Indexed (BX or BP) + (SI or DI)
2096 Based Indexed + Displacement (BX or BP) + (SI or DI) + Displacement
2097 The displacement can be a 0, 8 or 16-bit value.
2100 Figure 2-13. Complex Addressing Modes
2102 1. BASED MODE 2. INDEXED MODE
2104 MOV AX, [BP + DATE_CODE] MOV ID[SI], DX
2105 ADD[BX + BALANCE], CX SUB BX, DATA_TBL[SI]
2108 †�����������‡‘“ †�����������‡‘“ I
2110 ‚�����������ƒ Ñ‘‘‘‘‘‘‘‘‘‘ � ‚�����������ƒ Ñ‘‘‘‘‘‘‘‘‘‘ � E
2111 € DISPL Ñ‘‘‘
\x10€ OPERAND € –‘ € INDEX Ñ‘‘‘
\x10€ OPERAND € –‘D
2112 „�����������… Ñ‘‘‘‘‘‘‘‘‘‘ � „�����������… Ñ‘‘‘‘‘‘‘‘‘‘ �
2114 ‚�����������ƒ ’‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘• ‚�����������ƒ ’‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘• R
2115 € BASE Ñ• € € € DISPL Ñ• € € R
2116 „�����������… € € „�����������… € € A
2118 ‚�����������ƒ € € ‚�����������ƒ € €
2119 € SEGMENT Ñ‘‘‘
\x10„�����������… € SEGMENT Ñ‘‘‘
\x10„�����������…
2120 „�����������… „�����������…
2122 3. BASED INDEXED 4. BASED INDEXED MODE
2123 WITH DISPLACEMENT BASED
2124 MOV DX, [BP][DI] STRUCTURE
2125 AND [BX + SI], 3FFH MOV CX, [BP][SI + CNT] CONTAINING
2126 SHR[BX + DI + MASK] ARRAY
2128 †�����������‡‘“ A †�����������‡ ‘‘“�
2130 ‚�����������ƒ Ñ‘‘‘‘‘‘‘‘‘‘ � E ‚�����������ƒ Ñ‘‘‘‘‘‘‘‘‘‘‘“ ��
2131 € INDEX Ñ‘‘‘
\x10€ OPERAND € –‘D € INDEX Ñ‘‘“ €œœœœœœœœœœœ€ � A ��
2132 „�����������… Ñ‘‘‘‘‘‘‘‘‘‘ � „�����������… � Ñ‘‘‘‘‘‘‘‘‘‘ � R ��
2133 + € € � A + ”
\x10€ OPERAND € –‘R –•
2134 ‚�����������ƒ ’‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘• R ‚�����������ƒ ’‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘ � A �
2135 € BASE Ñ• € € R € DISPL Ñ• €œœœœœœœœœœœ€ � Y �
2136 „�����������… € € A „�����������… ’
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘• �
2138 ‚�����������ƒ € € ‚�����������ƒ � Ñ‘‘‘‘‘‘‘‘‘‘ ‘‘•
2139 € SEGMENT Ñ‘‘‘
\x10„�����������… € BASE Ñ‘‘• € €
2140 „�����������… „�����������… € €
2143 € SEGMENT Ñ‘‘‘
\x10„�����������…
2149 The 80286 allows input/output to be performed in either of two ways: by
2150 means of a separate I/O address space (using specific I/O instructions) or
2151 by means of memory-mapped I/O (using general-purpose operand manipulation
2155 2.5.1 I/O Address Space
2157 The 80286 provides a separate I/O address space, distinct from physical
2158 memory, to address the input/output ports that are used for external
2159 devices. The I/O address space consists of 2^(16) (64K) individually
2160 addressable 8-bit ports. Any two consecutive 8-bit ports can be treated as
2161 a 16-bit port. Thus, the I/O address space can accommodate up to 64K 8-bit
2162 ports or up to 32K 16-bit ports. I/O port addresses 00F8H to 00FFH are
2165 The 80286 can transfer either 8 or 16 bits at a time to a device located in
2166 the I/O space. Like words in memory, 16-bit ports should be aligned at
2167 even-numbered addresses so that the 16 bits will be transferred in a single
2168 access. An 8-bit port may be located at either an even or odd address. The
2169 internal registers in a given peripheral controller device should be
2170 assigned addresses as shown below.
2172 Port Register Port Addresses Example
2174 16-bit even word addresses OUT FE,AX
2176 lower half of 16-bit
2178 data bus even byte addresses IN AL,FE
2180 8-bit; device on upper
2181 half of 16-bit data bus odd byte addresses OUT FF,AL
2183 The I/O instructions IN and OUT (described in section 3.11.3) are provided
2184 to move data between I/O ports and the AX (16-bit I/O) or AL (8-bit I/O)
2185 general registers. The block I/O instructions INS and OUTS (described in
2186 section 4.1) move blocks of data between I/O ports and memory space (as
2187 shown below). In Protected Mode, an operating system may prevent a program
2188 from executing these I/O instructions. Otherwise, the function of the I/O
2189 instructions and the structure of the I/O space are identical for both modes
2192 INS es:byte ptr [di], DX
2193 OUTS DX, byte ptr [si]
2195 IN and OUT instructions address I/O with either a direct address to one of
2196 up to 256 port addresses, or indirectly via the DX register to one of up to
2197 64K port addresses. Block I/O uses the DX register to specify the I/O
2198 address and either SI or DI to designate the source or destination memory
2199 address. For each transfer, SI or DI are either incremented or decremented
2200 as specified by the direction bit in the flag word while DX is constant to
2201 select the I/O device.
2204 2.5.2 Memory-Mapped I/O
2206 I/O devices also may be placed in the 80286 memory address space. So long
2207 as the devices respond like memory components, they are indistinguishable to
2210 Memory-mapped I/O provides additional programming flexibility. Any
2211 instruction that references memory may be used to access an I/O port located
2212 in the memory space. For example, the MOV instruction can transfer data
2213 between any register and a port; and the AND, OR, and TEST instructions may
2214 be used to manipulate bits in the internal registers of a device (see
2215 figure 2-14). Memory-mapped I/O performed via the full instruction set
2216 maintains the full complement of addressing modes for selecting the desired
2219 Memory-mapped I/O, like any other memory reference, is subject to access
2220 protection and control when executing in protected mode.
2223 Figure 2-14. Memory-Mapped I/O
2227 ‚����������������ƒ I/O DEVICE 1
2228 € € ‚���������������������ƒ
2229 € € € INTERNAL REGISTER €
2230 Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ ‘‘ ‘ ‘‘ ‘ ‘‘ ‘€‘‚�����������������ƒ €
2232 Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ ‘‘ ‘ ‘‘ ‘ ‘‘ ‘€‘„�����������������… €
2233 € € „���������������������…
2236 € € ‚���������������������ƒ
2237 € € € INTERNAL REGISTER €
2238 €‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘€‘ ‘‘ ‘ ‘‘ ‘ ‘‘ ‘€‘‚�����������������ƒ €
2240 €‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘€‘ ‘‘ ‘ ‘‘ ‘ ‘‘ ‘€‘„�����������������… €
2241 € € „���������������������…
2246 2.6 Interrupts and Exceptions
2248 The 80286 architecture supports several mechanisms for interrupting program
2249 execution. Internal interrupts are synchronous events that are the responses
2250 of the CPU to certain events detected during the execution of an
2251 instruction. External interrupts are asynchronous events typically
2252 triggered by external devices needing attention. The 80286 supports both
2253 maskable (controlled by the IF flag) and non-maskable interrupts. They cause
2254 the processor to temporarily suspend its present program execution in order
2255 to service the requesting device. The major distinction between these two
2256 kinds of interrupts is their origin: an internal interrupt is always
2257 reproducible by re-executing with the program and data that caused the
2258 interrupt, whereas an external interrupt is generally independent of the
2259 currently executing task.
2261 Interrupts 0-31 are reserved by Intel.
2263 Application programmers will normally not be concerned with servicing
2264 external interrupts. More information on external interrupts for system
2265 programmers may be found in Chapter 5, section 5.2, "Interrupt Handling for
2266 Real Address Mode," and in Chapter 9, "Interrupts, Traps and Faults for
2267 Protected Virtual Address Mode."
2269 In Real Address Mode, the application programmer is affected by two kinds
2270 of internal interrupts. (Internal interrupts are the result of executing an
2271 instruction which causes the interrupt.) One type of interrupt is called an
2272 exception because the interrupt only occurs if a particular fault condition
2273 exists. The other type of interrupt generates the interrupt every time the
2274 instruction is executed.
2276 The exceptions are: divide error, INTO detected overflow, bounds check,
2277 segment overrun, invalid operation code, and processor extension error (see
2278 table 2-4). A divide error exception results when the instructions DIV or
2279 IDIV are executed with a zero denominator; otherwise, the quotient will be
2280 too large for the destination operand (see section 3.3.4 for a discussion
2281 of DIV and IDIV). An overflow exception results when the INTO instruction is
2282 executed and the OF flag is set (after an arithmetic operation that set the
2283 overflow (OF) flag). (See section 3.6.3, "Software Generated Interrupts,"
2284 for a discussion of INTO.) A bounds check exception results when the BOUND
2285 instruction is executed and the array index it checks falls outside the
2286 bounds of the array. (See section 4.2 for a discussion of the BOUND
2287 instruction.) The segment overrun exception occurs when a word memory
2288 reference is attempted which extends beyond the end of a segment. An invalid
2289 operation code exception occurs if an attempt is made to execute an
2290 undefined instruction operation code. A processor extension error is
2291 generated when a processor extension detects an illegal operation. Refer to
2292 Chapter 5 for a more complete description of these exception conditions.
2294 The instruction INT generates an internal interrupt whenever it is
2295 executed. The effects of this interrupt (and the effects of all interrupts)
2296 is determined by the interrupt handler routines provided by the application
2297 program or as part of the system software (provided by system programmers).
2298 See Chapter 5 for more on this topic. The INT instruction itself is
2299 discussed in section 3.6.3.
2301 In Protected Mode, many more fault conditions are detected and result in
2302 internal interrupts. Protected Mode interrupts and faults are discussed in
2306 2.7 Hierarchy of Instruction Sets
2308 For descriptive purposes, the 80286 instruction set is partitioned into
2309 three distinct subsets: the Basic Instruction Set, the Extended Instruction
2310 Set, and the System Control Instruction Set. The "hierarchy" of instruction
2311 sets defined by this partitioning helps to clarify the relationships
2312 between the various processors in the 8086 family (see figure 2-15).
2314 The Basic Instruction Set, presented in Chapter 3, comprises the common
2315 subset of instructions found on all processors of the 8086 family. Included
2316 are instructions for logical and arithmetic operations, data movement,
2317 input/output, string manipulation, and transfer of control.
2319 The Extended Instruction Set, presented in Chapter 4, consists of those
2320 instructions found only on the 80186, 80188, and 80286 processors. Included
2321 are instructions for block structured procedure entry and exit, parameter
2322 validation, and block I/O transfers.
2324 The System Control Instruction Set, presented in Chapter 10, consists of
2325 those instructions unique to the 80286. These instructions control the
2326 memory management and protection mechanisms of the 80286.
2329 Table 2-4. 80286 Interrupt Vector Assignments (Real Address Mode)
2332 Function Interupt Related Return Address
2333 Number Instructions Before Instruction
2335 Divide error exception 0 DIV, IDIV Yes
2336 Single step interrupt 1 All
2338 Breakpoint interrupt 3 INT
2339 INTO detected overflow exception 4 INTO No
2340 BOUND range exceeded exception 5 BOUND Yes
2341 Invalid opcode exception 6 Any undefined Yes
2343 Processor extension 7 ESC or WAIT Yes
2344 not available exception
2345 Interrupt table limit 8 INT vector Yes
2346 too small exception is not within
2348 Processor extension segment 9 ESC with memory No
2349 overrun interrupt operand extending
2353 Segment overrun exception 13 Word memory Yes
2360 Processor extension 16 ESC or WAIT
2367 Figure 2-15. Hierarchy of Instructions
2369 ‚����������������������ƒ
2372 € ‚����������������ƒ €
2374 € € ‚����������ƒ € €
2375 € € € 8086
\x11Α‘Α‘Α‘BASIC INSTRUCTION SET
2377 € € „����������… € €
2378 € € 80186
\x11‘‘‘Α‘Α‘EXTENDED INSTRUCTION SET
2380 € „����������������… €
2381 € 80286
\x11‘‘‘‘‘‘Α‘SYSTEM CONTROL INSTRUCTION SET
2383 „����������������������…
2386 Chapter 3 Basic Instruction Set
2388 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
2390 The base architecture of the 80286 is identical to the complete instruction
2391 set of the 8086, 8088, 80188, and 80186 processors. The 80286 instruction
2392 set includes new forms of some instructions. These new forms reduce program
2393 size and improve the performance and ease of implementation of source code.
2395 This chapter describes the instructions which programmers can use to write
2396 application software for the 80286. The following chapters describe the
2397 operation of more complicated I/O and system control instructions.
2399 All instructions described in this chapter are available for both Real
2400 Address Mode and Protected Virtual Address Mode operation. The instruction
2401 descriptions note any differences that exist between the operation of an
2402 instruction in these two modes.
2404 This chapter also describes the operation of each application
2405 program-relative instruction and includes an example of using the
2406 instruction. The Instruction Dictionary in Appendix B contains formal
2407 descriptions of all instructions. Any opcode pattern that is not described
2408 in the Instruction Dictionary is undefined and results in an opcode
2409 violation trap (interrupt 6).
2412 3.1 Data Movement Instructions
2414 These instructions provide convenient methods for moving bytes or words of
2415 data between memory and the registers of the base architecture.
2418 3.1.1 General-Purpose Data Movement Instructions
2420 MOV (Move) transfers a byte or a word from the source operand to the
2421 destination operand. The MOV instruction is useful for transferring data to
2422 a register from memory, to memory from a register, between registers,
2423 immediate-to-register, or immediate-to-memory. Memory-to-memory or segment
2424 register-to-segment register moves are not allowed.
2427 MOV DS,AX. Replaces the contents of register DS with the contents of
2430 XCHG (Exchange) swaps the contents of two operands. This instruction takes
2431 the place of three MOV instructions. It does not require a temporary memory
2432 location to save the contents of one operand while you load the other.
2434 The XCHG instruction can swap two byte operands or two word operands, but
2435 not a byte for a word or a word for a byte. The operands for the XCHG
2436 instruction may be two register operands, or a register operand with a
2437 memory operand. When used with a memory operand, XCHG automatically
2438 activates the LOCK signal.
2441 XCHG BX,WORDOPRND. Swaps the contents of register BX with the contents
2442 of the memory word identified by the label WORDOPRND after asserting
2446 3.1.2 Stack Manipulation Instructions
2448 PUSH (Push) decrements the stack pointer (SP) by two and then transfers a
2449 word from the source operand to the top of stack indicated by SP. See figure
2450 3-1. PUSH is often used to place parameters on the stack before calling a
2451 procedure; it is also the basic means of storing temporary variables on the
2452 stack. The PUSH instruction operates on memory operands, immediate operands
2453 (new with the 80286), and register operands (including segment registers).
2456 PUSH WORDOPRND. Transfers a 16-bit value from the memory word identified
2457 by the label WORDOPRND to the memory location which represents the current
2458 top of stack (byte transfers are not allowed).
2460 PUSHA (Push All Registers) saves the contents of the eight general
2461 registers on the stack. See figure 3-2. This instruction simplifies
2462 procedure calls by reducing the number of instructions required to retain
2463 the contents of the general registers for use in a procedure. PUSHA is
2464 complemented by POPA (see below).
2466 The processor pushes the general registers on the stack in the following
2467 order: AX, CX, DX, BX, the initial value of SP before AX was pushed, BP, SI,
2471 PUSHA. Pushes onto the stack the contents of the eight general registers.
2473 POP (Pop) transfers the word at the current top of stack (indicated by SP)
2474 to the destination operand, and then increments SP by two to point to the
2475 new top of stack. See figure 3-3. POP moves information from the stack to
2476 either a register or memory. The only restriction on POP is that it cannot
2477 place a value in register CS.
2480 POP BX. Replaces the contents of register BX with the contents of the
2481 memory location at the top of stack.
2483 POPA (Pop All Registers) restores the registers saved on the stack by
2484 PUSHA, except that it ignores the value of SP. See figure 3-4.
2487 POPA. Pops from the stack the saved contents of the general registers,
2488 and restores the registers (except SP) to their original state.
2494 HIGH ADDRESS € € € €
2495 †���������������‡ †���������������‡ SS LIMIT
2496 OPERANDS FROM €œœœœœœœœœœœœœœœ€ €œœœœœœœœœœœœœœœ€
2497 PREVIOUS PUSH †���������������‡ †���������������‡
2498 INSTRUCTIONS SP‘
\x10€œœœœœœœœœœœœœœœ€ €œœœœœœœœœœœœœœœ€
2499 †���������������‡ †���������������‡ SP ALWAYS POINTS
2500 € € € OPERAND €
\x11‘TO THE LAST WORD
2501 †���������������‡ †���������������‡ PUSHED ONTO THE
2503 †���������������‡ †���������������‡
2505 †���������������‡ †���������������‡
2506 € € € € SS ALWAYS POINTS
2507 LOW ADDRESS †���������������‡ †���������������‡ TO LOWEST ADDRESS
2508 € € € € USED BY THE STACK
2509 \a BEFORE
\a \a AFTER
\a
2510 PUSH OPERAND PUSH OPERAND
2512 PUSH decrements SP by 2 bytes and places the operand in the stack at the
2513 location to which SP points.
2519 HIGH ADDRESS € € € €
2520 †���������������‡ †���������������‡ SS LIMIT
2521 OPERANDS FROM €œœœœœœœœœœœœœœœ€ €œœœœœœœœœœœœœœœ€
2522 PREVIOUS PUSH †���������������‡ †���������������‡
2523 INSTRUCTIONS ’‘‘
\x10€œœœœœœœœœœœœœœœ€ €œœœœœœœœœœœœœœœ€
2524 � †���������������‡ †���������������‡
2526 †���������������‡ †���������������‡
2528 †���������������‡ †���������������‡
2530 †���������������‡ †���������������‡
2532 †���������������‡ †���������������‡
2534 †���������������‡ †���������������‡
2536 †���������������‡ †���������������‡
2538 †���������������‡ †���������������‡
2540 †���������������‡ †���������������‡
2542 †���������������‡ †���������������‡
2544 †���������������‡ †���������������‡
2546 †���������������‡ †���������������‡
2548 †���������������‡ †���������������‡
2550 LOW ADDRESS †���������������‡ †���������������‡ SS
2556 PUSHA copies the contents of the eight general registers to the stack in
2557 the above order. The instruction decrements SP by 16 bytes (8 words) to
2558 point to the last word pushed on the stack.
2564 HIGH ADDRESS € € € €
2565 †���������������‡ †���������������‡ SS LIMIT
2566 OPERANDS FROM €œœœœœœœœœœœœœœœ€ €œœœœœœœœœœœœœœœ€
2567 PREVIOUS PUSH †���������������‡ †���������������‡
2568 INSTRUCTIONS €œœœœœœœœœœœœœœœ€ €œœœœœœœœœœœœœœœ€
\x11‘‘‘SP
2569 †���������������‡ †���������������‡
2570 SP‘‘‘
\x10€ OPERAND € € €
2571 †���������������‡ †���������������‡
2573 †���������������‡ †���������������‡
2575 †���������������‡ †���������������‡
2577 LOW ADDRESS †���������������‡ †���������������‡ SS
2579 \a BEFORE
\a \a AFTER
\a
2580 POP OPERAND POP OPERAND
2582 POP copies the contents of the stack location before SP to the operand in
2583 the instruction. POP then increments SP by 2 bytes (1 word).
2588 HIGH ADDRESS € € € €
2589 †���������������‡ †���������������‡ SS LIMIT
2590 OPERANDS FROM €œœœœœœœœœœœœœœœ€ €œœœœœœœœœœœœœœœ€
2591 PREVIOUS PUSH †���������������‡ †���������������‡
2592 INSTRUCTIONS €œœœœœœœœœœœœœœœ€ €œœœœœœœœœœœœœœœ€
\x11‘‘‘SP
2593 †���������������‡ †���������������‡
2595 †���������������‡ †���������������‡
2597 †���������������‡ †���������������‡
2599 †���������������‡ †���������������‡
2601 †���������������‡ †���������������‡
2603 †���������������‡ †���������������‡
2605 †���������������‡ †���������������‡
2607 †���������������‡ †���������������‡
2609 †���������������‡ †���������������‡
2611 †���������������‡ †���������������‡
2613 †���������������‡ †���������������‡
2615 †���������������‡ †���������������‡
2617 †���������������‡ †���������������‡
2619 LOW ADDRESS †���������������‡ †���������������‡ SS
2620 \a BEFORE
\a \a AFTER
\a
2623 POPA copies the contents of seven stack locations to the corresponding
2624 general registers. POPA discards the stored value of SP.
2627 3.2 Flag Operation With the Basic Instruction Set
2632 The status flags of the FLAGS register reflect conditions that result from
2633 a previous instruction or instructions. The arithmetic instructions use OF,
2634 SF, ZF, AF, PF, and CF.
2636 The SCAS (Scan String), CMPS (Compare String), and LOOP instructions use ZF
2637 to signal that their operations are complete. The base architecture includes
2638 instructions to set, clear, and complement CF before execution of an
2639 arithmetic instruction. See figure 3-5 and tables 3-1 and 3-2.
2644 The control flags of the FLAGS register determine processor operations for
2645 string instructions, maskable interrupts, and debugging.
2647 Setting DF (direction flag) causes string instructions to auto-decrement;
2648 that is, to process strings from high addresses to low addresses, or from
2649 "right-to-left." Clearing DF causes string instructions to auto-increment,
2650 or to process strings from "left-to-right."
2652 Setting IF (interrupt flag) allows the CPU to recognize external (maskable)
2653 interrupt requests. Clearing IF disables these interrupts. IF has no effect
2654 on either internally generated interrupts, nonmaskable external interrupts,
2655 or processor extension segment overrun interrupts.
2657 Setting TF (trap flag) puts the processor into single-step mode for
2658 debugging. In this mode, the CPU automatically generates an internal
2659 interrupt after each instruction, allowing a program to be inspected as it
2660 executes each instruction, instruction by instruction.
2663 Table 3-1. Status Flags' Functions
2665 Bit Position Name Function
2667 0 CF Carry Flag--Set on high-order bit carry or borrow;
2670 2 PF Parity Flag--Set if low-order eight bits of result
2671 contain an even number of 1 bits; cleared otherwise
2673 4 AF Set on carry from or borrow to the low order four
2674 bits of AL; cleared otherwise
2676 6 ZF Zero Flag--Set if result is zero; cleared otherwise
2678 7 SF Sign Flag--Set equal to high-order bit of result (0
2679 if positive, 1 if negative)
2681 11 OF Overflow Flag--Set if result is too-large a positive
2682 number or too-small a negative number (excluding
2683 sign-bit) to fit in destination operand; cleared
2687 Table 3-2. Control Flags' Functions
2689 Bit Position Name Function
2691 8 TF Trap (Single Step) Flag--Once set, a single step
2692 interrupt occurs after the next instruction executes.
2693 TF is cleared by the single step interrupt.
2695 9 IF Interrupt-enable Flag--When set, maskable interrupts
2696 will cause the CPU to transfer control to an interrupt
2697 vector-specified location.
2699 10 DF Direction Flag--Causes string instructions to auto
2700 decrement the appropriate index registers when set.
2701 Clearing DF causes auto increment.
2704 Figure 3-5. Flag Word Contents
2707 CARRY‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
2708 PARITY‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“ �
2709 AUXILLIARY CARRY‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“ � �
2710 ZERO‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“ � � �
2711 SIGN‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“ � � � �
2712 OVERFLOW‘‘‘‘‘‘‘‘‘‘‘‘“ � � � � �
2714 15 14 13 12
\x1f11 10 9 8
\x1f 7
\x1f 6 5
\x1f 4 3
\x1f 2 1
\x1f 0
2715 ‚��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��ƒ
2716 FLAGS:€œœ�NT�IOPL �OF�DF�IF�TF�SF�ZF�œœ�AF�œœ�PF�œœ�CF€
2717 „��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��…
2718 \x1e \x1e \x1e \x1e \x1e
2719 � � � � � CONTROL FLAGS:
2720 � � � � ”‘‘‘‘‘‘‘‘‘‘‘TRAP FLAG
2721 � � � ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘INTERRUPT ENABLE
2722 � � ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘DIRECTION FLAG
2724 � ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘I/O PRIVILEGE LEVEL
2725 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘NESTED TASK FLAG
2728 3.3 Arithmetic Instructions
2730 The arithmetic instructions of the 8086-family processors simplify the
2731 manipulation of numerical data. Multiplication and division instructions
2732 ease the handling of signed and unsigned binary integers as well as unpacked
2735 An arithmetic operation may consist of two register operands, a general
2736 register source operand with a memory destination operand, a memory source
2737 operand with a register destination operand, or an immediate field with
2738 either a register or memory destination operand, but not two memory
2739 operands. Arithmetic instructions can operate on either byte or word
2743 3.3.1 Addition Instructions
2745 ADD (Add Integers) replaces the destination operand with the sum of the
2746 source and destination operands. ADD affects OF, SF, AF, PF, CF, and ZF.
2749 ADD BL, BYTEOPRND. Adds the contents of the memory byte labeled
2750 BYTEOPRND to the contents of BL, and replaces BL with the resulting sum.
2752 ADC (Add Integers with Carry) sums the operands, adds one if CF is set, and
2753 replaces the destination operand with the result. ADC can be used to add
2754 numbers longer than 16 bits. ADC affects OF, SF, AF, PF, CF, and ZF.
2757 ADC BX, CX. Replaces the contents of the destination operand BX with
2758 the sum of BX, CS, and 1 (if CF is set). If CF is cleared, ADC
2759 performs the same operation as the ADD instruction.
2761 INC (Increment) adds one to the destination operand. The processor treats
2762 the operand as an unsigned binary number. INC updates AF, OF, PF, SF, and
2763 ZF, but it does not affect CF. Use ADD with an immediate value of 1 if an
2764 increment that updates carry (CF) is needed.
2767 INC BL. Adds 1 to the contents of BL.
2770 3.3.2 Subtraction Instructions
2772 SUB (Subtract Integers) subtracts the source operand from the destination
2773 operand and replaces the destination operand with the result. If a borrow is
2774 required, carry flag is set. The operands may be signed or unsigned bytes or
2775 words. SUB affects OF, SF, ZF, AF, PF, and CF.
2778 SUB WORDOPRND, AX. Replaces the contents of the destination operand
2779 WORDOPRND with the result obtained by subtracting the contents of AX from
2780 the contents of the memory word labeled WORDOPRND.
2782 SBB (Subtract Integers with Borrow) subtracts the source operand from the
2783 destination operand, subtracts 1 if CF is set, and returns the result to the
2784 destination operand. The operands may be signed or unsigned bytes or words.
2785 SBB may be used to subtract numbers longer than 16 bits. This instruction
2786 affects OF, SF, ZF, AF, PF, and CF. The carry flag is set if a borrow is
2790 SBB BL, 32. Subtracts 32 from the contents of BL and then decrements the
2791 result of this subtraction by one if CF is set. If CF is cleared, SBB
2792 performs the same operation as SUB.
2794 DEC (Decrement) subtracts 1 from the destination operand. DEC updates AF,
2795 OF, PF, SF, and ZF, but it does not affect CF. Use SUB with an immediate
2796 value of 1 to perform a decrement that affects carry.
2799 DEC BX. Subtracts 1 from the contents of BX and places the result back in
2803 3.3.3 Multiplication Instructions
2805 MUL (Unsigned Integer Multiply) performs an unsigned multiplication of the
2806 source operand and the accumulator. If the source is a byte, the processor
2807 multiplies it by the contents of AL and returns the double-length result to
2810 If the source operand is a word, the processor multiplies it by the
2811 contents of AX and returns the double-length result to DX and AX. MUL sets
2812 CF and OF to indicate that the upper half of the result is nonzero;
2813 otherwise, they are cleared. This instruction leaves SF, ZF, AF, and PF
2817 MUL BX. Replaces the contents of DX and AX with the product of BX and AX.
2818 The low-order 16 bits of the result replace the contents of AX; the
2819 high-order word goes to DX. The processor sets CF and OF if the unsigned
2820 result is greater than 16 bits.
2822 IMUL (Signed Integer Multiply) performs a signed multiplication operation.
2823 IMUL uses AX and DX in the same way as the MUL instruction, except when used
2824 in the immediate form.
2826 The immediate form of IMUL allows the specification of a destination
2827 register other than the combination of DX and AX. In this case, the result
2828 cannot exceed 16 bits without causing an overflow. If the immediate operand
2829 is a byte, the processor automatically extends it to 16 bits before
2830 performing the multiplication.
2832 The immediate form of IMUL may also be used with unsigned operands because
2833 the low 16 bits of a signed or unsigned multiplication of two 16-bit values
2834 will always be the same.
2836 IMUL clears CF and OF to indicate that the upper half of the result is the
2837 sign of the lower half. This instruction leaves SF, ZF, AF, and PF
2841 IMUL BL. Replaces the contents of AX with the product of BL and AL. The
2842 processor sets CF and OF if the result is more than 8 bits long.
2845 IMUL BX, SI, 5. Replaces the contents of BX with the product of the
2846 contents of SI and an immediate value of 5. The processor sets CF and OF
2847 if the signed result is longer than 16 bits.
2850 3.3.4 Division Instructions
2852 DIV (Unsigned Integer Divide) performs an unsigned division of the
2853 accumulator by the source operand. If the source operand is a byte, it is
2854 divided into the double-length dividend assumed to be in registers AL and AH
2855 (AH = most significant byte; AL = least significant byte). The
2856 single-length quotient is returned in AL, and the single-length remainder is
2859 If the source operand is a word, it is divided into the double-length
2860 dividend in registers AX and DX. The single-length quotient is returned in
2861 AX, and the single-length remainder is returned in DX. Non-integral
2862 quotients are truncated to integers toward 0. The remainder is always less
2865 For unsigned byte division, the largest quotient is 255. For unsigned word
2866 division, the largest quotient is 65,535. DIV leaves OF, SF, ZF, AF, PF, and
2867 CF undefined. Interrupt (INT 0) occurs if the divisor is zero or if the
2868 quotient is too large for AL or AX.
2871 DIV BX. Replaces the contents of AX with the unsigned quotient of the
2872 doubleword value contained in DX and AX, divided by BX. The unsigned
2873 modulo replaces the contents of DX.
2876 DIV BL. Replaces the contents of AL with the unsigned quotient of the
2877 word value in AX, divided by BL. The unsigned modulo replaces the
2880 IDIV (Signed Integer Divide) performs a signed division of the accumulator
2881 by the source operand. IDIV uses the same registers as the DIV instruction.
2883 For signed byte division, the maximum positive quotient is +127 and the
2884 minimum negative quotient is -128. For signed word division, the maximum
2885 positive quotient is +32,767 and the minimum negative quotient is -32,768.
2886 Non-integral results are truncated towards 0. The remainder will always
2887 have the same sign as the dividend and will be less than the divisor in
2888 magnitude. IDIV leaves OF, SF, ZF, AF, PF, and CF undefined. A division by
2889 zero causes an interrupt (INT 0) to occur if the divisor is 0 or if the
2890 quotient is too large for AL or AX.
2893 IDIV WORDOPRND. Replaces the contents of AX with the signed quotient
2894 of the double-word value contained in DX and AX, divided by the value
2895 contained in the memory word labeled WORDOPRND. The signed modulo
2896 replaces the contents of DX.
2899 3.4 Logical Instructions
2901 The group of logical instructions includes the Boolean operation
2902 instructions, rotate and shift instructions, type conversion instructions,
2903 and the no-operation (NOP)instruction.
2906 3.4.1 Boolean Operation Instructions
2908 Except for the NOT and NEG instructions, the Boolean operation instructions
2909 can use two register operands, a general purpose register operand with a
2910 memory operand, an immediate operand with a general purpose register
2911 operand, or a memory operand. The NOT and NEG instructions are unary
2912 operations that use a single operand in a register or memory.
2914 AND (And) performs the logical "and" of the operands (byte or word) and
2915 returns the result to the destination operand. AND clears OF and DF, leaves
2916 AF undefined, and updates SF, ZF, and PF.
2919 AND WORDOPRND, BX. Replaces the contents of WORDOPRND with the logical
2920 "and" of the contents of the memory word labeled WORDOPRND and the
2923 NOT (Not) inverts the bits in the specified operand to form a one's
2924 complement of the operand. NOT has no effect on the flags.
2927 NOT BYTEOPRND. Replaces the original contents of BYTEOPRND with the
2928 one's complement of the contents of the memory word labeled BYTEOPRND.
2930 OR (Or) performs the logical "inclusive or" of the two operands and returns
2931 the result to the destination operand. OR clears OF and DF, leaves AF
2932 undefined, and updates SF, ZF, and PF.
2935 OR AL,5. Replaces the original contents of AL with the logical
2936 "inclusive or" of the contents of AL and the immediate value 5.
2938 XOR (Exclusive OR) performs the logical "exclusive or" of the two operands
2939 and returns the result to the destination operand. XOR clears OF and DF,
2940 leaves AF undefined, and updates SF, ZF, and PF.
2943 XOR DX, WORDOPRND. Replaces the original contents of DX with the logical
2944 "exclusive or" or the contents of DX and the contents of the memory word
2947 NEG (Negate) forms a two's complement of a signed byte or word operand. The
2948 effect of NEG is to reverse the sign of the operand from positive to
2949 negative or from negative to positive. NEG updates OF, SF, ZF, AF, PF, and
2953 NEG AX. Replaces the original contents of AX with the two's complement
2954 of the contents of AX.
2957 3.4.2 Shift and Rotate Instructions
2959 The shift and rotate instructions reposition the bits within the specified
2960 operand. The shift instructions provide a convenient way to accomplish
2961 division or multiplication by binary power. The rotate instructions are
2962 useful for bit testing.
2965 3.4.2.1 Shift Instructions
2967 The bits in bytes and words may be shifted arithmetically or logically.
2968 Depending on the value of a specified count, up to 31 shifts may be
2971 A shift instruction can specify the count in one of three ways. One form of
2972 shift instruction implicitly specifies the count as a single shift. The
2973 second form specifies the count as an immediate value. The third form
2974 specifies the count as the value contained in CL. This last form allows the
2975 shift count to be a variable that the program supplies during execution.
2976 Only the low order 5 bits of CL are used.
2978 Shift instructions affect the flags as follows. AF is always undefined
2979 following a shift operation. PF, SF, and ZF are updated normally as in the
2980 logical instructions.
2982 CF always contains the value of the last bit shifted out of the destination
2983 operand. In a single-bit shift, OF is set if the value of the high-order
2984 (sign) bit was changed by the operation. Otherwise, OF is cleared. Following
2985 a multibit shift, however, the content of OF is always undefined.
2987 SAL (Shift Arithmetic Left) shifts the destination byte or word operand left
2988 by one or by the number of bits specified in the count operand (an immediate
2989 value or the value contained in CL). The processor shifts zeros in from the
2990 right side of the operand as bits exit from the left side. See figure 3-6.
2993 SAL BL,2. Shifts the contents of BL left by 2 bits and replaces the two
2994 low-order bits with zeros.
2997 SAL BL,1. Shifts the contents of BL left by 1 bit and replaces the
2998 low-order bit with a zero. Because the processor does not have to decode
2999 the immediate count operand to obtain the shift count, this from of the
3000 instruction takes 2 clock cycles rather than the 6 clock cycles (5 + 1
3001 cycle for each bit shifted) required by the previous example.
3003 SHL (Shift Logical Left) is physically the same instruction as SAL (see SAL
3006 SHR (Shift Logical Right) shifts the destination byte or word operand right
3007 by one or by the number of bits specified in the count operand (an immediate
3008 value or the value contained in CL). The processor shifts zeros in from the
3009 left side of the operand as bits exit from the right side. See figure 3-7.
3012 SHR BYTEOPRND, CL. Shifts the contents of the memory byte labeled
3013 BYTEOPRND right by the number of bits specified in CL, and pads the left
3014 side of BYTEOPRND with an equal number of zeros.
3016 SAR (Shift Arithmetic Right) shifts the destination byte or word operand to
3017 the right by one or by the number of bits specified in the count operand (an
3018 immediate value or the value contained in CL). The processor preserves the
3019 sign of the operand by shifting in zeros on the left side if the value is
3020 positive or by shifting by ones if the value is negative. See figure 3-8.
3023 SAR WORDPRND,1. Shifts the contents of the memory byte labeled WORDPRND
3024 right by one, and replaces the high-order sign bit with a value equal to
3025 the original sign of WORDPRND.
3027 SHR shifts the bits in the register or memory operand to the right by the
3028 specified number of bit positions. CF receives the last bit shifted out of
3029 the right of the operand. SHR shifts in zeros to fill the vacated bit
3030 locations. This instruction operates on byte operands as well as word
3034 Figure 3-6. SAL and SHL
3037 ‚�ƒ ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ
3038 €X€ €X€ € 1 € 1 € 1 € 1 € 1 € 0 € 0 € 0 € 1 € 1 € 1 € 1 € 0 € 0 € 1 € 1 €
3039 „�… „�… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���…
3041 AFTER SAL OR SHL BY 1 BIT
3042 ‚�ƒ ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ
3043 €0€ €1€
\x11‘Â 1 € 1 € 1 € 1 € 0 € 0 € 0 € 1 € 1 € 1 € 1 € 0 € 0 € 1 € 1 € 0 €
3044 „�… „�… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���…
3046 AFTER SAL OR SHL BY 8 BITS
3047 ‚�ƒ ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ
3048 €X€ € €
\x11‘Â 1 € 1 € 1 € 1 € 0 € 0 € 1 € 1 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 €
3049 „�… „�… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���…
3052 Both SAL and SHL shift the bits in the register or memory operand to the
3053 left by the specified number of bit positions. CF receives the last bit
3054 shifted out of the left of the operand. SAL and SHL shift in zeros to fill
3055 the vacated bit locations. These instructions operate on byte operands as
3056 well as word operands.
3062 ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚�ƒ
3063 €X€ € 1 € 1 € 0 € 0 € 1 € 1 € 1 € 1 € 0 € 1 € 1 € 1 € 0 € 0 € 0 € 1 € €X€
3064 „�… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���… „�…
3067 ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚�ƒ
3068 €1€ € 0 € 1 € 1 € 0 € 0 € 1 € 1 € 1 € 1 € 0 € 1 € 1 € 1 € 0 € 0 € 0 Ñ
\x10€1€
3069 „�… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���… „�…
3071 AFTER SHR BY 10 BITS
3072 ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚�ƒ
3073 €X€ € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 1 € 1 € 0 € 0 € 1 Ñ
\x10€1€
3074 „�… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���… „�…
3077 SHR shifts the bits in the register or memory operand to the right by the
3078 specified number of bit positions. CF receives the last bit shifted out of
3079 the right of the operand. SHR shifts in zeros to fill the vacated bit
3080 locations. This instruction operates on byte operands as well as word
3086 BEFORE SAR WITH A POSITIVE OPERAND
3087 ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚�ƒ
3088 €X€ € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 1 € €X€
3089 „�… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���… „�…
3091 AFTER SAR WITH A POSITIVE OPERAND SHIFTED 1 BIT
3092 ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚�ƒ
3093 €X€ € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 € 0 Ñ
\x10€1€
3094 „�… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���… „�…
3096 BEFORE SAR WITH A NEGATIVE OPERAND
3097 ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚�ƒ
3098 €X€ € 1 € 0 € 0 € 0 € 1 € 1 € 1 € 1 € 0 € 0 € 0 € 1 € 1 € 0 € 1 € 0 Ñ
\x10€X€
3099 „�… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���… „�…
3101 AFTER SAR WITH A NEGATIVE OPERAND SHIFTED 6 BITS
3102 ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚�ƒ
3103 €X€ € 1 € 1 € 1 € 1 € 1 € 1 € 1 € 0 € 0 € 0 € 1 € 1 € 1 € 1 € 0 € 0 Ñ
\x10€0€
3104 „�… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���… „�…
3107 SAR preserves the sign of the register or memory operand as it shifts the
3108 operand to the right the specified number of bit positions. CF receives the
3109 last bit shifted out of the right of the operand. This instruction also
3110 operates on byte operands.
3113 3.4.2.2 Rotate Instructions
3115 Rotate instructions allow bits in bytes and words to be rotated. Bits
3116 rotated out of an operand are not lost as in a shift, but are "circled" back
3117 into the other "end" of the operand.
3119 Rotates affect only the carry and overflow flags. CF may act as an
3120 extension of the operand in two of the rotate instructions, allowing a bit
3121 to be isolated and then tested by a conditional jump instruction (JC or
3122 JNC). CF always contains the value of the last bit rotated out, even if the
3123 instruction does not use this bit as an extension of the rotated operand.
3125 In single-bit rotates, OF is set if the operation changes the high-order
3126 (sign) bit of the destination operand. If the sign bit retains its original
3127 value, OF is cleared. On multibit rotates, the value of OF is always
3130 ROL (Rotate Left) rotates the byte or word destination operand left by one
3131 or by the number of bits specified in the count operand (an immediate value
3132 or the value contained in CL). For each rotation specified, the high-order
3133 bit that exists from the left of the operand returns at the right to become
3134 the new low-order bit of the operand. See figure 3-9.
3137 ROL AL, 8. Rotates the contents of AL left by 8 bits. This rotate
3138 instruction returns AL to its original state but isolates the low-order
3139 bit in CF for testing by a JC or JNC instruction.
3141 ROR (Rotate Right) rotates the byte or word destination operand right by
3142 one or by the number of bits specified in the count operand (an immediate
3143 value or the value contained in CL). For each rotation specified, the
3144 low-order bit that exits from the right of the operand returns at the left
3145 to become the new high-order bit of the operand. See figure 3-10.
3148 ROR WORDOPRND, CL. Rotates the contents of the memory word labeled
3149 WORDOPRND by the number of bits specified by the value contained in CL.
3150 CF reflects the value of the last bit rotated from the right to the left
3151 side of the operand.
3153 RCL (Rotate Through Carry Left) rotates bits in the byte or word
3154 destination operand left by one or by the number of bits specified in the
3155 count operand (an immediate value or the value contained in CL).
3157 This instruction differs from ROL in that it treats CF as a high-order
3158 1-bit extension of the destination operand. Each high-order bit that exits
3159 from the left side of the operand moves to CF before it returns to the
3160 operand as the low-order bit on the next rotation cycle. See figure 3-11.
3163 RCL BX,1. Rotates the contents of BX left by one bit. The high-order bit
3164 of the operand moves to CF, the remaining 15 bits move left one position,
3165 and the original value of CF becomes the new low-order bit.
3167 RCR (Rotate Through Carry Right) rotates bits in the byte or word
3168 destination operand right by one or by the number of bits specified in the
3169 count operand (an immediate value or the value contained in CL).
3171 This instruction differs from ROR in that it treats CF as a low-order 1-bit
3172 extension of the destination operand. Each low-order bit that exits from the
3173 right side of the operand moves to CF before it returns to the operand as
3174 the high-order bit on the next rotation cycle. See figure 3-12.
3177 RCR BYTEOPRND,3. Rotates the contents of the memory byte labeled BYTEOPRND
3178 to the right by 3 bits. Following the execution of this instruction, CF
3179 reflects the original value of bit number 5 of BYTEOPRND, and the original
3180 value of CF becomes bit 2.
3182 RCL rotates the bits in the memory or register operand to the left in the
3183 same way as ROL except that RCL treats CF as a 1-bit extension of the
3184 operand. Note that a 16-bit RCL produces the same result as a 1-bit RCR
3185 (though it takes much longer to execute). This instruction also operates on
3188 RCR rotates the bits in the memory or register operand to the right in the
3189 same way as ROR except that RCR treats CF as a 1-bit extension of the
3190 operand. This instruction also operates on byte operands.
3196 ‚�ƒ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ
3197 €X€€X€ € 1 € 0 € 0 € 0 € 1 € 1 € 1 € 0 € 1 € 0 € 0 € 1 € 1 € 0 € 0 € 0 €
3198 „�…„�… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���…
3201 ‚�ƒ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ
3202 €1€€1€
\x11˜Â 0 € 0 € 0 € 1 € 1 € 1 € 0 € 1 € 0 € 0 € 1 € 1 € 0 € 0 € 0 € 1
\x11“
3203 „�…„�… �„���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���…�
3204 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
3206 AFTER ROL BY 12 BITS
3207 ‚�ƒ‚�ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ
3208 €X€€1€
\x11˜Â 1 € 0 € 0 € 0 € 1 € 0 € 0 € 0 € 1 € 1 € 1 € 0 € 1 € 0 € 0 € 1
\x11“
3209 „�…„�… �„���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���…�
3211 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
3213 ROL shifts the bits in the memory or register operand to the left by the
3214 specified number of bit positions. It copies the bit shifted out of the
3215 left of the operand into the right of the operand. The last bit shifted
3216 into the least significant bit of the operand also appears in CF. This
3217 instruction also operates on byte operands.
3223 ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚���ƒ
3224 € 1 € 1 € 0 € 1 € 1 € 1 € 0 € 0 € 1 € 0 € 1 € 1 € 1 € 0 € 0 € 0 € € X €
3225 „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���… „���…
3228 ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚���ƒ
3229 ’
\x10 0 € 1 € 1 € 0 € 1 € 1 € 1 € 0 € 0 € 1 € 0 € 1 € 1 € 1 € 0 € 0 Ø
\x10€ 0 €
3230 �„���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���…� „���…
3231 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
3234 ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚���ƒ
3235 ’
\x10 1 € 0 € 1 € 1 € 1 € 0 € 0 € 0 € 1 € 1 € 0 € 1 € 1 € 1 € 0 € 0 Ø
\x10€ 1 €
3236 �„���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���…� „���…
3238 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
3240 ROR shifts the bits in the memory or register operand to the right by the
3241 specified number of bit positions. It copies each bit shifted out of the
3242 right of the operand into the left of the operand. The last bit shifted
3243 into the most significant bit of the operand also appears in CF. This
3244 instruction also operates on byte operands.
3250 ‚���ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ
3251 € 1 € € 1 € 1 € 1 € 0 € 0 € 0 € 1 € 1 € 0 € 0 € 1 € 1 € 0 € 0 € 0 € 0 €
3252 „���… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���…
3255 ‚���ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ
3256 ’‘Â 1 €
\x11‘Â 1 € 1 € 0 € 0 € 0 € 1 € 1 € 0 € 0 € 1 € 1 € 0 € 0 € 0 € 0 € 1
\x11“
3257 � „���… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���…�
3258 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
3260 AFTER RCL BY 16 BITS
3261 ‚���ƒ ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ
3262 ’‘Â 0 €
\x11‘Â 1 € 1 € 1 € 1 € 0 € 0 € 0 € 1 € 1 € 0 € 0 € 1 € 1 € 0 € 0 € 0
\x11“
3263 � „���… „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���…�
3265 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
3267 RCL rotates the bits in the memory or register operand to the left in the
3268 same way as ROL except that RCL treats CF as a 1-bit extension of the
3269 operand. Note that a 16-bit RCL produces the same result as a 1-bit RCR
3270 (though it takes much longer to execute). This instruction also operates
3277 ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚���ƒ
3278 € 1 € 1 € 1 € 0 € 0 € 0 € 1 € 1 € 0 € 0 € 1 € 1 € 0 € 0 € 0 € 0 € € 1 €
3279 „���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���… „���…
3282 ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚���ƒ
3283 ’
\x10 1 € 1 € 1 € 1 € 0 € 0 € 0 € 1 € 1 € 0 € 0 € 1 € 1 € 0 € 0 € 0 Ñ
\x10€ 0 Ñ“
3284 �„���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���… „���… �
3285 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
3288 ‚���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ˆ���ƒ ‚���ƒ
3289 ’
\x10 0 € 0 € 1 € 1 € 1 € 1 € 0 € 0 € 0 € 1 € 1 € 0 € 0 € 1 € 1 € 0 Ñ
\x10€ 0 Ñ“
3290 �„���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���‰���… „���… �
3292 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
3294 RCR rotates the bits in the memory or register operand to the right in the
3295 same way as ROR except that RCR treats CF as a 1-bit extension of the
3296 operand. This instruction also operates on byte operands.
3299 3.4.3 Type Conversion and No-Operation Instructions
3301 The type conversion instructions prepare operands for division. The NOP
3302 instruction is a 1-byte filler instruction with no effect on registers or
3305 CWD (Convert Word to Double-Word) extends the sign of the word in register
3306 AX throughout register DX. CWD does not affect any flags. CWD can be used to
3307 produce a double-length (double-word) dividend from a word before a word
3310 CBW (Convert Byte to Word) extends the sign of the byte in register AL
3311 throughout AX. CBW does not affect any flags.
3314 CWD. Sign-extends the 16-bit value in AX to a 32-bit value in DX and AX
3315 with the high-order 16-bits occupying DX.
3317 NOP (No Operation) occupies a byte of storage but affects nothing but the
3318 instruction pointer, IP. The amount of time that a NOP instruction requires
3319 for execution varies in proportion to the CPU clocking rate. This variation
3320 makes it inadvisable to use NOP instructions in the construction of timing
3321 loops because the operation of such a program will not be independent of the
3322 system hardware configuration.
3325 NOP. The processor performs no operation for 2 clock cycles.
3328 3.5 Test and Compare Instructions
3330 The test and compare instructions are similar in that they do not alter
3331 their operands. Instead, these instructions perform operations that only set
3332 the appropriate flags to indicate the relationship between the two operands.
3334 TEST (Test) performs the logical "and" of the two operands, clears OF and
3335 DF, leaves AF undefined, and updates SF, ZF, and PF. The difference between
3336 TEST and AND is that TEST does not alter the destination operand.
3339 TEST BL,32. Performs a logical "and" and sets SF, ZF, and PF according to
3340 the results of this operation. The contents of BL remain unchanged.
3342 CMP (Compare) subtracts the source operand from the destination operand. It
3343 updates OF, SF, ZF, AF, PF, and CF but does not alter the source and
3344 destination operands. A subsequent signed or unsigned conditional transfer
3345 instruction can test the result using the appropriate flag result.
3347 CMP can compare two register operands, a register operand and a memory
3348 operand, a register operand and an immediate operand, or an immediate
3349 operand and a memory operand. The operands may be words or bytes, but CMP
3350 cannot compare a byte with a word.
3353 CMP BX,32. Subtracts the immediate operand, 32, from the contents of BX
3354 and sets OF, SF, ZF, AF, PF, and CF to reflect the result. The contents
3355 of BX remain unchanged.
3358 3.6 Control Transfer Instructions
3360 The 80286 provides both conditional and unconditional program transfer
3361 instructions to direct the flow of execution. Conditional program transfers
3362 depend on the results of operations that affect the flag register.
3363 Unconditional program transfers are always executed.
3366 3.6.1 Unconditional Transfer Instructions
3368 JMP, CALL, RET, INT and IRET instructions transfer control from one code
3369 segment location to another. These locations can be within the same code
3370 segment or in different code segments.
3373 3.6.1.1 Jump Instruction
3375 JMP (Jump) unconditionally transfers control to the target location. JMP is
3376 a one-way transfer of execution; it does not save a return address on the
3379 The JMP instruction always performs the same basic function of transferring
3380 control from the current location to a new location. Its implementation
3381 varies depending on the following factors:
3383 Ž Is the address specified directly within the instruction or indirectly
3384 through a register or memory?
3386 Ž Is the target location inside or outside the current code segment
3389 A direct JMP instruction includes the destination address as part of the
3390 instruction. An indirect JMP instruction obtains the destination address
3391 indirectly through a register or a pointer variable.
3393 Control transfers through a gate or to a task state segment are available
3394 only in Protected Mode operation of the 80286. The formats of the
3395 instructions that transfer control through a call gate, a task gate, or to a
3396 task state segment are the same. The label included in the instruction
3397 selects one of these three paths to a new code segment.
3399 Direct JMP within the current code segment. A direct JMP that transfers
3400 control to a target location within the current code segment uses a relative
3401 displacement value contained in the instruction. This can be either a 16-bit
3402 value or an 8-bit value sign extended to 16 bits. The processor forms an
3403 effective address by adding this relative displacement to the address
3404 contained in IP. IP refers to the next instruction when the additions are
3408 JMP NEAR_NEWCODE. Transfers control to the target location labeled
3409 NEAR_NEWCODE, which is within the code segment currently selected in CS.
3411 Indirect JMP within the current code segment. Indirect JMP instructions
3412 that transfer control to a location within the current code segment specify
3413 an absolute address in one of several ways. First, the program can JMP to a
3414 location specified by a 16-bit register (any of AX, DX, CX, BX, BP, SI, or
3415 DI). The processor moves this 16-bit value into IP and resumes execution.
3418 JMP SI. Transfers control to the target address formed by adding the
3419 16-bit value contained in SI to the base address contained in CS.
3421 The processor can also obtain the destination address within a current
3422 segment from a memory word operand specified in the instruction.
3425 JMP PTR_X. Transfers control to the target address formed by adding the
3426 16-bit value contained in the memory word labeled PTR X to the base
3427 address contained in CS.
3429 A register can modify the address of the memory word pointer to select a
3430 destination address.
3433 JMP CASE_TABLE [BX]. CASE_TABLE is the first word in an array of word
3434 pointers. The value of BX determines which pointer the program selects
3435 from the array. The JMP instruction then transfers control to the
3436 location specified by the selected pointer.
3438 Direct JMP outside of the current code segment. Direct JMP instructions
3439 that specify a target location outside the current code segment contain a
3440 full 32-bit pointer. This pointer consists of a selector for the new code
3441 segment and an offset within the new segment.
3444 JMP FAR_NEWCODE_FOO. Places the selector contained in the instruction into
3445 CS and the offset into IP. The program resumes execution at this location
3446 in the new code segment.
3448 Indirect JMP outside of the current code segment. Indirect JMP instructions
3449 that specify a target location outside the current code segment use a
3450 double-word variable to specify the pointer.
3453 JMP NEWCODE. NEWCODE the first word of two consecutive words in memory
3454 which represent the new pointer. NEWCODE contains the new offset for IP
3455 and the word following NEWCODE contains the selector for CS. The program
3456 resumes execution at this location in the new code segment. (Protected
3457 mode programs treat this differently. See Chapters 6 and 7).
3459 Direct JMP outside of the current code segment to a call gate. If the
3460 selector included with the instruction refers to a call gate, then the
3461 processor ignores the offset in the instruction and takes the pointer of the
3462 routine being entered from the call gate.
3464 JMP outside of current code segment may only go to the same level.
3467 JMP CALL_GATE_FOO. The selector in the instruction refers to the call gate
3468 CALL_GATE_FOO, and the call gate actually provides the new contents of CS
3469 and IP to specify the address of the next instructions.
3471 Indirect JMP outside the current code segment to a call gate. If the
3472 selector specified by the instruction refers to a call gate, the processor
3473 ignores the offset in the double-word and takes the address of the routine
3474 being entered from the call gate. The JMP instruction uses the same format
3475 to indirectly specify a task gate or a task state segment.
3478 JMP CASE_TABLE [BX]. The instruction refers to the double-word in the
3479 array of pointers called CASE_TABLE. The specific double-word chosen
3480 depends on the value in BX when the instruction executes. The selector
3481 portion of this double-word selects a call gate, and the processor takes
3482 the address of the routine being entered from the call gate.
3484 ROL shifts the bits in the memory or register operand to the left by the
3485 specified number of bit positions. It copies the bit shifted out of the left
3486 of the operand into the right of the operand. The last bit shifted into the
3487 least significant bit of the operand also appears in CF. This instruction
3488 also operates on byte operands.
3490 ROR shifts the bits in the memory or register operand to the right by the
3491 specified number of bit positions. It copies each bit shifted out of the
3492 right of the operand into the left of the operand. The last bit shifted into
3493 the most significant bit of the operand also appears in CF. This instruction
3494 also operates on byte operands.
3497 3.6.1.2 Call Instruction
3499 CALL (Call Procedure) activates an out-of-line procedure, saving on the
3500 stack the address of the instruction following the CALL for later use by a
3501 RET (Return) instruction. An intrasegment CALL places the current value of
3502 IP on the stack. An intersegment CALL places both the value of IP and CS on
3503 the stack. The RET instruction in the called procedure uses this address to
3504 transfer control back to the calling program.
3506 A long CALL instruction that invokes a task-switch stores the outgoing
3507 task's task state segment selector in the incoming task state segment's link
3508 field and sets the nested task flag in the new task. In this case, the IRET
3509 instruction takes the place of the RET instruction to return control to the
3516 CALL CASE_TABLE [BP]
3517 CALL FAR_NEWCODE_FOO
3520 CALL CASE_TABLE [BX]
3522 See the previous treatment of JMP for a discussion of the operations of
3526 3.6.1.3 Return And Return From Interrupt Instruction
3528 RET (Return From Procedure) terminates the execution of a procedure and
3529 transfers control through a back-link on the stack to the program that
3530 originally invoked the procedure.
3532 An intrasegment RET restores the value of IP that was saved on the stack by
3533 the previous intrasegment CALL instruction. An intersegment RET restores the
3534 values of both CS and IP which were saved on the stack by the previous
3535 intersegment CALL instruction.
3537 RET instructions may optionally specify a constant to the stack pointer.
3538 This constant specifies the new top of stack to effectively remove any
3539 arguments that the calling program pushed on the stack before the execution
3540 of the CALL instruction.
3543 RET. If the previous CALL instruction did not transfer control to a new
3544 code segment, RET restores the value of IP pushed by the CALL instruction.
3545 If the previous CALL instruction transferred control to a new segment, RET
3546 restores the values of both IP and CS which were pushed on the stack by
3547 the CALL instruction.
3550 RET n. This form of the RET instruction performs identically to the above
3551 example except that it adds n (which must be an even value) to the value
3552 of SP to eliminate n bytes of parameter information previously pushed by
3553 the calling program.
3555 IRET (Return From Interrupt or Nested Task) returns control to an
3556 interrupted routine or, optionally, reverses the action of a CALL or INT
3557 instruction that caused a task switch. See Chapter 8 for further
3558 information on task switching.
3561 IRET. Returns from an interrupt with or without a task switch based on
3562 the value of the NT bit.
3565 3.6.2 Conditional Transfer Instructions
3567 The conditional transfer instructions are jumps that may or may not transfer
3568 control, depending on the state of the CPU flags when the instruction
3569 executes. Instruction encoding is most efficient when the target for the
3570 conditional jumps is in the current code segment and within -128 to +127
3571 bytes of the first byte of the next instruction. Alternatively, the opposite
3572 sense of the conditional jump can skip around an unconditional jump to the
3576 3.6.2.1 Conditional Jump Instructions
3578 Table 3-3 shows the conditional transfer mnemonics and their
3579 interpretations. The conditional jumps that are listed as pairs are actually
3580 the same instruction. The assembler provides the alternate mnemonics for
3581 greater clarity within a program listing.
3584 Table 3-3. Interpretation of Conditional Transfers
3586 Unsigned Conditional Transfers
3587 Mnemonic Condition Tested "Jump If. . ."
3589 JA/JNBE (CF or ZF) = 0 above/not below nor equal
3590 JAE/JNB CF = 0 above or equal/not below
3591 JB/JNAE CF = 1 below/not above nor equal
3592 JBE/JNA (CF or ZF) = 1 below or equal/not above
3594 JE/JZ ZF = 1 equal/zero
3595 JNC CF = 0 not carry
3596 JNE/JNZ ZF = 0 not equal/not zero
3597 JNP/JPO PF = 0 not parity/parity odd
3598 JP/JPE PF = 1 parity/parity even
3600 Signed Conditional Transfers
3601 Mnemonic Condition Tested "Jump If. . ."
3603 JG/JNLE ((SF xor OF) or ZF) = 0 greater/not less nor equal
3604 JGE/JNL (SF xor OF) = 0 greater or equal/not less
3605 JL/JNGE (SF xor OF) = 0 less/not greater nor equal
3606 JLE/JNG ((SF xor OF) or ZF) = 1 less or equal/not greater
3607 JNO OF = 0 not overflow
3608 JNS SF = 0 not sign (positive, including 0)
3610 JS SF = 1 sign (negative)
3613 3.6.2.2 Loop Instructions
3615 The loop instructions are conditional jumps that use a value placed in CX
3616 to specify the number of repetitions of a software loop. All loop
3617 instructions automatically decrement CX and terminate the loop when CX=0.
3618 Four of the five loop instructions specify a condition of ZF that
3619 terminates the loop before CX decrements to zero.
3621 LOOP (Loop While CX Not Zero) is a conditional transfer that
3622 auto-decrements the CX register before testing CX for the branch condition.
3623 If CX is non-zero, the program branches to the target label specified in the
3624 instruction. The LOOP instruction causes the repetition of a code section
3625 until the operation of the LOOP instruction decrements CX to a value of
3626 zero. If LOOP finds CX=0, control transfers to the instruction immediately
3627 following the LOOP instruction. If the value of CX is initially zero, then
3628 the LOOP executes 65,536 times.
3631 LOOP START_LOOP. Each time the program encounters this instruction, it
3632 decrements CX and then tests it. If the value of CX is non-zero, then the
3633 program branches to the instruction labeled START_LOOP. If the value in CX
3634 is zero, then the program continues with the instruction that follows the
3637 LOOPE (Loop While Equal) and LOOPZ (Loop While Zero) are physically the
3638 same instruction. These instructions auto-decrement the CX register before
3639 testing CX and ZF for the branch conditions. If CX is non-zero and ZF=1, the
3640 program branches to the target label specified in the instruction. If LOOPE
3641 or LOOPZ finds that CX=0 or ZF=0, control transfers to the instruction
3642 immediately succeeding the LOOPE or LOOPZ instruction.
3645 LOOPE START_LOOP (or LOOPZ START_LOOP). Each time the program encounters
3646 this instruction, it decrements CX and tests CX and ZF. If the value in
3647 CX is non-zero and the value of ZF is 1, the program branches to the
3648 instruction labeled START_LOOP. If CX=0 or ZF=0, the program continues
3649 with the instruction that follows the LOOPE (or LOOPZ) instruction.
3651 LOOPNE (Loop While Not Equal) and LOOPNZ (Loop While Not Zero) are
3652 physically the same instruction. These instructions auto-decrement the CX
3653 register before testing CX and ZF for the branch conditions. If CX is
3654 non-zero and ZF=0, the program branches to the target label specified in
3655 the instruction. If LOOPNE or LOOPNZ finds that CX=0 or ZF=1, control
3656 transfers to the instruction immediately succeeding the LOOPNE or LOOPNZ
3660 LOOPNE START_LOOP (or LOOPNZ START_LOOP). Each time the program encounters
3661 this instruction, it decrements CX and tests CX and ZF. If the value of CX
3662 is non-zero and the value of ZF is 0, the program branches to the
3663 instruction labeled START_LOOP. If CX=0 or ZF=1, the program continues
3664 with the instruction that follows the LOOPNE (or LOOPNZ) instruction.
3667 3.6.2.3 Executing a Loop or Repeat Zero Times
3669 JCXZ (Jump if CX Zero) branches to the label specified in the instruction
3670 if it finds a value of zero in CX. Sometimes, it is desirable to design a
3671 loop that executes zero times if the count variable in CX is initialized to
3672 zero. Because the LOOP instructions (and repeat prefixes) decrement CX
3673 before they test it, a loop will execute 65,536 times if the program enters
3674 the loop with a zero value in CX. A programmer may conveniently overcome
3675 this problem with JCXZ, which enables the program to branch around the code
3676 within the loop if CX is zero when JCXZ executes.
3679 JCXZ TARGETLABEL. Causes the program to branch to the instruction labeled
3680 TARGETLABEL if CX=0 when the instruction executes.
3683 3.6.3 Software-Generated Interrupts
3685 The INT n and INTO instructions allow the programmer to specify a transfer
3686 to an interrupt service routine from within a program. Interrupts 0-31 are
3690 3.6.3.1 Software Interrupt Instruction
3692 INT n (Software Interrupt) activates the interrupt service routine that
3693 corresponds to the number coded within the instruction. Interrupt type 3 is
3694 reserved for internal software-generated interrupts. However, the INT
3695 instruction may specify any interrupt type to allow multiple types of
3696 internal interrupts or to test the operation of a service routine. The
3697 interrupt service routine terminates with an IRET instruction that returns
3698 control to the instruction that follows INT.
3701 INT 3. Transfers control to the interrupt service routine specified by a
3705 INT 0. Transfers control to the interrupt service routine specified by a
3706 type 0 interrupt, which is reserved for a divide error.
3708 INTO (Interrupt on Overflow) invokes a type 4 interrupt if OF is set when
3709 the INTO instruction executes. The type 4 interrupt is reserved for this
3713 INTO. If the result of a previous operation has set OF and no intervening
3714 operation has reset OF, then INTO invokes a type 4 interrupt. The
3715 interrupt service routine terminates with an IRET instruction, which
3716 returns control to the instruction following INTO.
3719 3.7 Character Translation and String Instructions
3721 The instructions in this category operate on characters or string elements
3722 rather than on logical or numeric values.
3725 3.7.1 Translate Instruction
3727 XLAT (Translate) replaces a byte in the AL register with a byte from a
3728 user-coded translation table. When XLAT is executed, AL should have the
3729 unsigned index to the table addressed by BX. XLAT changes the contents of AL
3730 from table index to table entry. BX is unchanged. The XLAT instruction is
3731 useful for translating from one coding system to another, such as from
3732 ASCII to EBCDIC. The translate table may be up to 256 bytes long. The value
3733 placed in the AL register serves as an index to the location of the
3734 corresponding translation value. Used with a LOOP instruction, the XLAT
3735 instruction can translate a block of codes up to 64K bytes long.
3738 XLAT. Replaces the byte in AL with the byte from the translate table that
3739 is selected by the value in AL.
3742 3.7.2 String Manipulation Instructions and Repeat Prefixes
3744 The string instructions (also called primitives) operate on string elements
3745 to move, compare, and scan byte or word strings. One-byte repeat prefixes
3746 can cause the operation of a string primitive to be repeated to process
3747 strings as long as 64K bytes.
3749 The repeated string primitives use the direction flag, DF, to specify
3750 left-to-right or right-to-left string processing, and use a count in CX to
3751 limit the processing operation. These instructions use the register pair
3752 DS:SI to point to the source string element and the register pair ES:DI to
3753 point to the destination.
3755 One of two possible opcodes represent each string primitive, depending on
3756 whether it is operating on byte strings or word strings. The string
3757 primitives are generic and require one or more operands along with the
3758 primitive to determine the size of the string elements being processed.
3759 These operands do not determine the addresses of the strings; the addresses
3760 must already be present in the appropriate registers.
3762 Each repetition of a string operation using the Repeat prefixes includes
3763 the following steps:
3765 1. Acknowledge pending interrupts.
3767 2. Check CX for zero and stop repeating if CX is zero.
3769 3. Perform the string operation once.
3771 4. Adjust the memory pointers in DS:SI and ES:DI by incrementing SI
3772 and DI if DF is 0 or by decrementing SI and DI if DF is 1.
3774 5. Decrement CX (this step does not affect the flags).
3776 6. For SCAS (Scan String) and CMPS (Compare String), check ZF for a
3777 match with the repeat condition and stop repeating if the ZF fails to
3780 The Load String and Store String instructions allow a program to perform
3781 arithmetic or logical operations on string characters (using AX for word
3782 strings and AL for byte strings). Repeated operations that include
3783 instructions other than string primitives must use the loop instructions
3784 rather than a repeat prefix.
3787 3.7.2.1 String Movement Instructions
3789 REP (Repeat While CX Not Zero) specifies a repeated operation of a string
3790 primitive. The REP prefix causes the hardware to automatically repeat the
3791 associated string primitive until CX=0. This form of iteration allows the
3792 CPU to process strings much faster than would be possible with a regular
3795 When the REP prefix accompanies a MOVS instruction, it operates as a
3796 memory-to-memory block transfer. To set up for this operation, the program
3797 must initialize CX and the register pairs DS:SI and ES:DI. CX specifies the
3798 number of bytes or words in the block.
3800 If DF=0, the program must point DS:SI to the first element of the source
3801 string and point ES:DI to the destination address for the first element. If
3802 DF=1, the program must point these two register pairs to the last element of
3803 the source string and to the destination address for the last element,
3807 REP MOVSW. The processor checks the value in CX for zero. If this value is
3808 not zero, the processor moves a word from the location pointed to by DS:SI
3809 to the location pointed to by ES:DI and increments SI and DI by two (if
3810 DF=0). Next, the processor decrements CX by one and returns to the
3811 beginning of the repeat cycle to check CX again. After CX decrements to
3812 zero, the processor executes the instruction that follows.
3814 MOVS (Move String) moves the string character pointed to by the combination
3815 of DS and SI to the location pointed to by the combination of ES and DI.
3816 This is the only memory-to-memory transfer supported by the instruction set
3817 of the base architecture. MOVSB operates on byte elements. The destination
3818 segment register cannot be overridden by a segment override prefix while
3819 the source segment register can be overridden.
3822 MOVSW. Moves the contents of the memory byte pointed to by DS:SI to the
3823 location pointed to by ES:DI.
3826 3.7.2.2 Other String Operations
3828 CMPS (Compare Strings) subtracts the destination string element (ES:DI)
3829 from the source string element (DS:SI) and updates the flags AF, SF, PF, CF
3830 and OF. If the string elements are equal, ZF=1; otherwise, ZF=0. If DF=0,
3831 the processor increments the memory pointers (SI and DI) for the two
3832 strings. The segment register used for the source address can be changed
3833 with a segment override prefix, while the destination segment register
3834 cannot be overridden.
3837 CMPSB. Compares the source and destination string elements with each other
3838 and returns the result of the comparison to ZF.
3840 SCAS (Scan String) subtracts the destination string element at ES:DI from
3841 AX or AL and updates the flags AF, SF, ZF, PF, CF and OF. If the values are
3842 equal, ZF=1; otherwise, ZF=0. If DF=0, the processor increments the memory
3843 pointer (DI) for the string. The segment register used for the source
3844 address can be changed with a segment override prefix while the destination
3845 segment register cannot be overridden.
3848 SCASW. Compares the value in AX with the destination string element.
3850 REPE/REPZ (Repeat While CX Equal/Zero) and REPNE/REPNZ (Repeat While CX Not
3851 Equal/Not Zero) are the prefixes that are used exclusively with the SCAS
3852 (ScanString) and CMPS (Compare String) primitives.
3854 The difference between these two types of prefix bytes is that REPE/REPZ
3855 terminates when ZF=0 and REPNE/REPNZ terminates when ZF=1. ZF does not
3856 require initialization before execution of a repeated string instruction.
3858 When these prefixes modify either the SCAS or CMPS primitives, the
3859 processor compares the value of the current string element with the value in
3860 AX for word elements or with the value in AL for byte elements. The
3861 resulting state of ZF can then limit the operation of the repeated
3862 operation as well as a zero value in CX.
3865 REPE SCASB. Causes the processor to scan the string pointed to by ES:DI
3866 until it encounters a match with the byte value in AL or until CX
3869 LODS (Load String) places the source string element at DS:SI into AX for
3870 word strings or into AL for byte strings.
3873 LODSW. Loads AX with the value pointed to by DS:SI.
3876 3.8 Address Manipulation Instructions
3878 The set of address manipulation instructions provide a way to perform
3879 address calculations or to move to a new data segment or extra segment.
3881 LEA (Load Effective Address) transfers the offset of the source operand
3882 (rather than its value) to the destination operand. The source operand must
3883 be a memory operand, and the destination operand must be a 16-bit general
3884 register (AX, DX, BX, CX, BP, SP, SI, or DI).
3886 LEA does not affect any flags. This instruction is useful for initializing
3887 the registers before the execution of the string primitives or the XLAT
3891 LEA BX EBCDIC_TABLE. Causes the processor to place the address of the
3892 starting location of the table labeled EBCDIC_TABLE into BX.
3894 LDS (Load Pointer Using DS) transfers a 32-bit pointer variable from the
3895 source operand to DS and the destination register. The source operand must
3896 be a memory operand, and the destination operand must be a 16-bit general
3897 register (AX, DX, BX, CX, BP, SP, SI or DI). DS receives the high-order
3898 segment word of the pointer. The destination register receives the
3899 low-order word, which points to a specific location within the segment.
3902 LDS SI, STRING_X. Loads DS with the word identifying the segment pointed
3903 to by STRING_X, and loads the offset of STRING_X into SI. Specifying SI as
3904 the destination operand is a convenient way to prepare for a string
3905 operation on a source string that is not in the current data segment.
3907 LES (Load Pointer Using ES) operates identically to LDS except that ES
3908 receives the offset word rather than DS.
3911 LES DI, DESTINATION_X. Loads ES with the word identifying the segment
3912 pointed to by DESTINATION_X, and loads the offset of DESTINATION_X into
3913 DI. This instruction provides a convenient way to select a destination for
3914 a string operation if the desired location is not in the current extra
3918 3.9 Flag Control Instructions
3920 The flag control instructions provide a method of changing the state of
3921 bits in the flag register.
3924 3.9.1 Carry Flag Control Instructions
3926 The carry flag instructions are useful in conjunction with
3927 rotate-with-carry instructions RCL and RCR. They can initialize the carry
3928 flag, CF, to a known state before execution of a rotate that moves the carry
3929 bit into one end of the rotated operand.
3931 STC (Set Carry Flag) sets the carry flag (CF) to 1.
3936 CLC (Clear Carry Flag) zeros the carry flag (CF).
3941 CMC (Complement Carry Flag) reverses the current status of the carry flag
3948 3.9.2 Direction Flag Control Instructions
3950 The direction flag control instructions are specifically included to set or
3951 clear the direction flag, DF, which controls the left-to-right or
3952 right-to-left direction of string processing. IF DF=0, the processor
3953 automatically increments the string memory pointers, SI and DI, after each
3954 execution of a string primitive. If DF=1, the processor decrements these
3955 pointer values. The initial state of DF is 0.
3957 CLD (Clear Direction Flag) zeros DF, causing the string instructions to
3958 auto-increment SI and/or DI. CLD does not affect any other flags.
3963 STD (Set Direction Flag) sets DF to 1, causing the string instructions to
3964 auto-decrement SI and/or DI. STD does not affect any other flags.
3970 3.9.3 Flag Transfer Instructions
3972 Though specific instructions exist to alter CF and DF, there is no direct
3973 method of altering the other flags. The flag transfer instructions allow a
3974 program to alter the other flag bits with the bit manipulation instructions
3975 after transferring these flags to the stack or the AH register.
3977 The PUSHF and POPF instructions are also useful for preserving the state of
3978 the flag register before executing a procedure.
3980 LAHF (Load AH from Flags) copies SF, ZF, AF, PF, and CF to AH bits 7, 6, 4,
3981 2, and 0, respectively (see figure 3-13). The contents of the remaining
3982 bits (5, 3, and 1) are undefined. The flags remain unaffected. This
3983 instruction can assist in converting 8080/8085 assembly language programs to
3984 run on the base architecture of the 8086, 8088, 80186, 80188, and 80286.
3989 SAHF (Store AH into Flags) transfers bits 7, 6, 4, 2, and 0 from AH into
3990 SF, ZF, AF, PF, and CF, respectively (see figure 3-13). This instruction
3991 also provides 8080/8085 compatibility with the 8086, 8088, 80186, 80188, and
3997 PUSHF (Push Flags) decrements SP by two and then transfers all flags to the
3998 word at the top of stack pointed to by SP (see figure 3-14). The flags
3999 remain unaffected. This instruction enables a procedure to save the state of
4000 the flag register for later use.
4005 POPF (Pop Flags) transfers specific bits from the word at the top of stack
4006 into the low-order byte of the flag register (see figure 3-14). The
4007 processor then increments SP by two.
4009 Note that an application program in the protected virtual address mode may
4010 not alter IOPL (the I/O privilege level flag) unless the program is
4011 executing at privilege level 0. A program may alter IF (the interrupt flag)
4012 only when executing at a level that is at least as privileged as IOPL.
4014 Procedures may use this instruction to restore the flag status from a
4021 Figure 3-13. LAHF and SAHF
4024 ‚����Ð����Ð����Ð����Ð����Ð����Ð����Ð����ƒ
4025 € SF � ZF �œœœœ� AF �œœœœ� PF �œœœœ� CF €
4026 „����¤����¤����¤����¤����¤����¤����¤����…
4029 LAHF loads five flags from the flag register into register AH. SAHF stores
4030 these same five flgs from AH into the flag register. The bit position of
4031 each flag is the same in AH as it is in the flag register. The remaining
4032 bits are indeterminate.
4035 Figure 3-14. PUSHF and POPF
4037 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
4038 ‚���Ð���Ð���Ð���Ð���Ð���Ð���Ð���Ð���Ð���Ð���Ð���Ð���Ð���Ð���Ð���ƒ
4039 €œœœ�NT � IOPL �OF �DF �IF �TF �SF �ZF �œœœ�AF �œœœ�PF �œœœ�CF €
4040 „���¤���¤���¤���¤���¤���¤���¤���¤���¤���¤���¤���¤���¤���¤���¤���…
4043 PUSHF decrements SP by 2 bytes (1 word) and copies the contents of the flag
4044 register to the top of the stack. POPF loads the flag register with the
4045 contents of the last word pushed onto the stack. The bit position of each
4046 flag is the same in the stack word as it is in the flag register. Only
4047 programs executing at the highest privilege level (level 0) may alter the
4048 2-bit IOPL flag. Only programs executing at a level at least as privileged
4049 as that indicated by IOPL may alter IF.
4052 3.10 Binary-Coded Decimal Arithmetic Instructions
4054 These instructions adjust the results of a previous arithmetic operation to
4055 produce a valid packed or unpacked decimal result. These instructions
4056 operate only on AL or AH registers.
4059 3.10.1 Packed BCD Adjustment Instructions
4061 DAA (Decimal Adjust) corrects the result of adding two valid packed decimal
4062 operands in AL. DAA must always follow the addition of two pairs of packed
4063 decimal numbers (one digit in each nibble) to obtain a pair of valid packed
4064 decimal digits as results. The carry flag will be set if carry was needed.
4069 DAS (Decimal Adjust for Subtraction) corrects the result of subtracting two
4070 valid packed decimal operands in AL. DAS must always follow the subtraction
4071 of one pair of packed decimal numbers (one digit in each nibble) from
4072 another to obtain a pair of valid packed decimal digits as results. The
4073 carry flag will be set if a borrow was needed.
4079 3.10.2 Unpacked BCD Adjustment Instructions
4081 AAA (ASCII Adjust for Addition) changes the contents of register AL to a
4082 valid unpacked decimal number, and zeros the top 4 bits. AAA must always
4083 follow the addition of two unpacked decimal operands in AL. The carry flag
4084 will be set and AH will be incremented if a carry was necessary.
4089 AAS (ASCII Adjust for Subtraction) changes the contents of register AL to a
4090 valid unpacked decimal number, and zeros the top 4 bits. AAS must always
4091 follow the subtraction of one unpacked decimal operand from another in AL.
4092 The carry flag will be set and AH decremented if a borrow was necessary.
4097 AAM (ASCII Adjust for Multiplication) corrects the result of a
4098 multiplication of two valid unpacked decimal numbers. AAM must always follow
4099 the multiplication of two decimal numbers to produce a valid decimal result.
4100 The high order digit will be left in AH, the low order digit in AL.
4105 AAD (ASCII Adjust for Division) modifies the numerator in AH and AL to
4106 prepare for the division of two valid unpacked decimal operands so that the
4107 quotient produced by the division will be a valid unpacked decimal number.
4108 AH should contain the high-order digit and AL the low-order digit. This
4109 instruction will adjust the value and leave it in AL. AH will contain 0.
4115 3.11 Trusted Instructions
4117 When operating in Protected Mode (Chapter 6 and following), the 80286
4118 processor restricts the execution of trusted instructions according to the
4119 Current Privilege Level (CPL) and the current value of IOPL, the 2-bit I/O
4120 privilege flag. Only a program operating at the highest privilege level
4121 (level 0) may alter the value of IOPL. A program may execute trusted
4122 instructions only when executing at a level that is at least as privileged
4123 as that specified by IOPL.
4125 Trusted instructions control I/O operations, interprocessor communications
4126 in a multiprocessor system, interrupt enabling, and the HLT instruction.
4128 These protection considerations do not apply in the real address mode.
4131 3.11.1 Trusted and Privileged Restrictions on POPF and IRET
4133 POPF (POP Flags) and IRET (Interrupt Return) are not affected by IOPL
4134 unless they attempt to alter IF (flag register bit 9). To change IF, POPF
4135 must be part of a program that is executing at a privilege level greater
4136 than or equal to that specified by IOPL. Any attempt to change IF when
4137 CPL � 0 will be ignored (i.e., the IF flag will be ignored). To change the
4138 IOPL field, CPL must be zero.
4141 3.11.2 Machine State Instructions
4143 These trusted instructions affect the machine state control interrupt
4144 response, the processor halt state, and the bus LOCK signal that regulates
4145 memory access in multiprocessor systems.
4147 CLI (Clear Interrupt-Enable Flag) and STI (Set Interrupt-Enable Flag) alter
4148 bit 9 in the flag register. When IF=0, the processor responds only to
4149 internal interrupts and to non-maskable external interrupts. When IF=1, the
4150 processor responds to all interrupts. An interrupt service routine might
4151 use these instructions to avoid further interruption while it processes a
4152 previous interrupt request. As with the other flag bits, the processor
4153 clears IF during initialization. These instructions may be executed only if
4154 CPL ¾ IOPL. A protection exception will occur if they are executed when
4158 STI. Sets IF=1, which enables the processing of maskable external
4162 CLI. Sets IF=0 to disable maskable interrupt processing.
4164 HLT (Halt) causes the processor to suspend processing operations pending an
4165 interrupt or a system reset. This trusted instruction provides an
4166 alternative to an endless software loop in situations where a program must
4167 wait for an interrupt. The return address saved after the interrupt will
4168 point to the instruction immediately following HLT. This instruction may be
4169 executed only when CPL = 0.
4174 LOCK (Assert Bus Lock) is a 1-byte prefix code that causes the processor to
4175 assert the bus LOCK signal during execution of the instruction that follows.
4176 LOCK does not affect any flags. LOCK may be used only when CPL ¾ IOPL. A
4177 protection exception will occur if LOCK is used when CPL > IOPL.
4180 3.11.3 Input and Output Instructions
4182 These trusted instructions provide access to the processor's I/O ports to
4183 transfer data to and from peripheral devices. In Protected Mode, these
4184 instructions may be executed only when CPL ¾ IOPL.
4186 IN (Input from Port) transfers a byte or a word from an input port to AL or
4187 AX. If a program specifies AL with the IN instruction, the processor
4188 transfers 8 bits from the selected port to AL. Alternately, if a program
4189 specifies AX with the IN instruction, the processor transfers 16 bits from
4192 The program can specify the number of the port in two ways. Using an
4193 immediate byte constant, the program can specify 256 8-bit ports numbered 0
4194 through 255 or 128 16-bit ports numbered 0,2,4,...,252,254. Using the
4195 current value contained in DX, the program can specify 8-bit ports numbered
4196 0 through 65,535, or 16-bit ports using even-numbered ports in the same
4201 BYTE_PORT_NUMBER. Transfers 8 bits to AL from the port identified by the
4202 immediate constant BYTE_PORT_NUMBER.
4204 OUT (Output to Port) transfers a byte or a word to an output port from AL
4205 or AX. The program can specify the number of the port using the same methods
4206 of the IN instruction.
4209 OUT AX, DX. Transfers 16 bits from AX to the port identified by the 16-bit
4210 number contained in DX.
4212 INS and OUTS (Input String and Output String) cause block input or output
4213 operations using a Repeat prefix. See Chapter 4 for more information on INS
4217 3.12 Processor Extension Instructions
4219 Processor Extension provides an extension to the instruction set of the
4220 base architecture (e.g., 80287). The NPX extends the instruction set of the
4221 CPU-based architecture to support high-precision integer and floating-point
4222 calculations. This extended instruction set includes arithmetic,
4223 comparison, transcendental, and data transfer instructions. The NPX also
4224 contains a set of useful constants to enhance the speed of numeric
4227 A program contains instructions for the NPX in line with the instructions
4228 for the CPU. The system executes these instructions in the same order as
4229 they appear in the instruction stream. The NPX operates concurrently with
4230 the CPU to provide maximum throughput for numeric calculations.
4232 The software emulation of the NPX is transparent to application software
4233 but requires more time for execution.
4236 3.12.1 Processor Extension Synchronization Instructions
4238 Escape and wait instructions allow a processor extension such as the 80287
4239 NPX to obtain instructions and data from the system bus and to wait for the
4240 NPX to return a result.
4242 ESC (Escape) identifies floating point numeric instructions and allows the
4243 80286 to send the opcode to the NPX or to transfer a memory operand to the
4244 NPX. The 80287 NPX uses the Escape instructions to perform high-performance,
4245 high-precision floating point arithmetic that conforms to the IEEE floating
4249 ESC 6, ARRAY [SI]. The CPU sends the escape opcode 6 and the location of
4250 the array pointed to by SI to the NPX.
4252 WAIT (Wait) suspends program execution until the 80286 CPU detects a signal
4253 on the BUSY pin. In a configuration that includes a numeric processor
4254 extension, the NPX activates the BUSY pin to signal that it has completed
4255 its processing task and that the CPU may obtain the results.
4261 3.12.2 Numeric Data Processor Instructions
4263 This section describes the categories of instructions available with
4264 Numeric Data Processor systems that include a Numeric Processor Extension or
4265 a software emulation of this processor extension.
4268 3.12.2.1 Arithmetic Instructions
4270 The extended instruction set includes not only the four arithmetic
4271 operations (add, subtract, multiply, and divide), but also subtract-reversed
4272 and divide-reversed instructions. The arithmetic functions include square
4273 root, modulus, absolute value, integer part, change sign, scale exponent,
4274 and extract exponent instructions.
4277 3.12.2.2 Comparison Instructions
4279 The comparison operations are the compare, examine, and test instructions.
4280 Special forms of the compare instruction can optimize algorithms by allowing
4281 comparisons of binary integers with real numbers in memory.
4284 3.12.2.3 Transcendental Instructions
4286 The instructions in this group perform the otherwise time-consuming
4287 calculations for all common trigonometric, inverse trigonometric,
4288 hyperbolic, inverse hyperbolic, logarithmic, and exponential functions. The
4289 transcendental instructions include tangent, arctangent, 2 x-1, Y. log{2} X,
4290 and Y. log{2} (X+1).
4293 3.12.2.4 Data Transfer Instructions
4295 The data transfer instructions move operands among the registers and
4296 between a register and memory. This group includes the load, store, and
4297 exchange instructions.
4300 3.12.2.5 Constant Instructions
4302 Each of the constant instructions loads a commonly used constant into an
4303 NPX register. The values have a real precision of 64 bits and are accurate
4304 to approximately 19 decimal places. The constants loaded by these
4305 instructions include 0, 1, Pi, log{e} 10, log{2} e, log{10} 2, and log 2{e}.
4308 Chapter 4 Extended Instruction Set
4310 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
4312 The instructions described in this chapter extend the capabilities of the
4313 base architecture instruction set described in Chapter 3. These extensions
4314 consist of new instructions and variations of some instructions that are not
4315 strictly part of the base architecture (in other words, not included on the
4316 8086 and 8088). These instructions are also available on the 80186 and
4317 80188. The instruction variations, described in Chapter 3, include the
4318 immediate forms of the PUSH and MUL instructions, PUSHA, POPA, and the
4319 privilege level restrictions on POPF.
4321 New instructions described in this chapter include the string input and
4322 output instructions (INS and OUTS), the ENTER procedure and LEAVE procedure
4323 instructions, and the check index BOUND instruction.
4326 4.1 Block I/O Instructions
4328 REP, the Repeat prefix, modifies INS and OUTS (the string I/O instructions)
4329 to provide a means of transferring blocks of data between an I/O port and
4330 Memory. These block I/O instructions are string primitives. They simplify
4331 programming and increase the speed of data transfer by eliminating the need
4332 to use a separate LOOP instruction or an intermediate register to hold the
4335 INS and OUTS are trusted instructions. To use trusted instructions, a
4336 program must execute at a privilege level at least as privileged as that
4337 specified by the 2-bit IOPL flag (CPL ¾ IOPL). Any attempt by a
4338 less-privileged program to use a trusted instruction results in a
4339 protection exception. See Chapter 7 for information on protection concepts.
4341 One of two possible opcodes represents each string primitive depending on
4342 whether it operates on byte strings or word strings. After each transfer,
4343 the memory address in SI or DI is updated by 1 for byte values and by 2 for
4344 word values. The value in the DF field determines if SI or DI is to be auto
4345 incremented (DF=0) or auto decremented (DF=1).
4347 INS and OUTS use DX to specify I/O ports numbered 0 through 65,535 or
4348 16-bit ports using only even port addresses in the same range.
4350 INS (Input String from Port) transfers a byte or a word string element from
4351 an input port to memory. If a program specifies INSB, the processor
4352 transfers 8 bits from the selected port to the memory location indicated by
4353 ES:DI. Alternately, if a program specifies INSW, the processor transfers 16
4354 bits from the port to the memory location indicated by ES:DI. The
4355 destination segment register choice (ES) cannot be changed for the INS
4358 Combined with the REP prefix, INS moves a block of information from an
4359 input port to a series of consecutive memory locations.
4362 REP INSB. The processor repeatedly transfers 8 bits to the memory
4363 location indicated by ES:DI from the port selected by the 16-bit port
4364 number contained in DX. Following each byte transfer, the CPU
4365 decrements CX. The instruction terminates the block transfer when CX=0.
4366 After decrementing CX, the processor increments DI by one if DF=0. It
4367 decrements DI by one if DF=1.
4369 OUTS (Output String to Port) transfers a byte or a word string element to
4370 an output port from memory. Combined with the REP prefix, OUTS moves a block
4371 of information from a series of consecutive memory locations indicated by
4372 DS:SI to an output port.
4375 REP OUTS WSTRING. Assuming that the program declares WSTRING to be a
4376 word-length string element, the assembler uses the 16-bit form of the OUTS
4377 instruction to create the object code for the program. The processor
4378 repeatedly transfers words from the memory locations indicated by DI to
4379 the output port selected by the 16-bit port number in DX.
4381 Following each word transfer, the CPU decrements CX. The instruction
4382 terminates the block transfer when CX=0. After decrementing CX, the
4383 processor increments SI by two to point to the next word in memory if DF=0;
4384 it decrements SI by two if DF=1.
4387 4.2 High-Level Instructions
4389 The instructions in this section provide machine-language functions
4390 normally found only in high-level languages. These instructions include
4391 ENTER and LEAVE, which simplify the programming of procedures, and BOUND,
4392 which provides a simple method of testing an index against its predefined
4395 ENTER (Enter Procedure) creates the stack frame required by most
4396 block-structured high-level languages. A LEAVE instruction at the end of a
4397 procedure complements an ENTER at the beginning of the procedure to simplify
4398 stack management and to control access to variables for nested procedures.
4401 ENTER 2048,3. Allocates 2048 bytes of dynamic storage on the stack and
4402 sets up pointers to two previous stack frames in the stack frame that
4403 ENTER creates for this procedure.
4405 The ENTER instruction includes two parameters. The first parameter
4406 specifies the number of bytes of dynamic storage to be allocated on the
4407 stack for the routine being entered. The second parameter corresponds to the
4408 lexical nesting level (0-31) of the routine. (Note that the lexical level
4409 has no relationship to either the protection privilege levels or to the I/O
4412 The specified lexical level determines how many sets of stack frame
4413 pointers the CPU copies into the new stack frame from the preceding frame.
4414 This list of stack frame pointers is sometimes called the "display." The
4415 first word of the display is a pointer to the last stack frame. This
4416 pointer enables a LEAVE instruction to reverse the action of the previous
4417 ENTER instruction by effectively discarding the last stack frame.
4419 After ENTER creates the new display for a procedure, it allocates the
4420 dynamic storage space for that procedure by decrementing SP by the number of
4421 bytes specified in the first parameter. This new value of SP serves as a
4422 base for all PUSH and POP operations within that procedure.
4424 To enable a procedure to address its display, ENTER leaves BP pointing to
4425 the beginning of the new stack frame. Data manipulation instructions that
4426 specify BP as a base register implicitly address locations within the stack
4427 segment instead of the data segment. Two forms of the ENTER instruction
4428 exist: nested and non-nested. If the lexical level is 0, the non-nested form
4429 is used. Since the second operand is 0, ENTER pushes BP, copies SP to BP and
4430 then subtracts the first operand from SP. The nested form of ENTER occurs
4431 when the second parameter (lexical level) is not 0. Figure 4-1 gives the
4432 formal definition of ENTER.
4434 The main procedure (with other procedures nested within) operates at the
4435 highest lexical level, level 1. The first procedure it calls operates at the
4436 next deeper lexical level, level 2. A level 2 procedure can access the
4437 variables of the main program which are at fixed locations specified by the
4438 compiler. In the case of level 1, ENTER allocates only the requested dynamic
4439 storage on the stack because there is no previous display to copy.
4441 A program operating at a higher lexical level calling a program at a lower
4442 lexical level requires that the called procedure should have access to the
4443 variables of the calling program. ENTER provides this access through a
4444 display that provides addressability to the calling program's stack frame.
4446 A procedure calling another procedure at the same lexical level implies
4447 that they are parallel procedures and that the called procedure should not
4448 have access to the variables of the calling procedure. In this case, ENTER
4449 copies only that portion of the display from the calling procedure which
4450 refers to previously nested procedures operating at higher lexical levels.
4451 The new stack frame does not include the pointer for addressing the calling
4452 procedure's stack frame.
4454 ENTER treats a reentrant procedure as a procedure calling another procedure
4455 at the same lexical level. In this case, each succeeding iteration of the
4456 reentrant procedure can address only its own variables and the variables of
4457 the calling procedures at higher lexical levels. A reentrant procedure can
4458 always address its own variables; it does not require pointers to the stack
4459 frames of previous iterations.
4461 By copying only the stack frame pointers of procedures at higher lexical
4462 levels, ENTER makes sure that procedures access only those variables of
4463 higher lexical levels, not those at parallel lexical levels (see figure
4464 4-2). Figures 4-2a, 4-2b, 4-2c, and 4-2d demonstrate the actions of the
4465 ENTER instruction if the modules shown in figure 4-1 were to call one
4466 another in alphabetic order.
4468 Block-structured high-level languages can use the lexical levels defined by
4469 ENTER to control access to the variables of previously nested procedures.
4470 For example, if PROCEDURE A calls PROCEDURE B which, in turn, calls
4471 PROCEDURE C, then PROCEDURE C will have access to the variables of MAIN and
4472 PROCEDURE A, but not PROCEDURE B because they operate at the same lexical
4473 level. Following is the complete definition of the variable access for
4476 1. MAIN PROGRAM has variables at fixed locations.
4478 2. PROCEDURE A can access only the fixed variables of MAIN.
4480 3. PROCEDURE B can access only the variables of PROCEDURE A and MAIN.
4481 PROCEDURE B cannot access the variables of PROCEDURE C or PROCEDURE D.
4483 4. PROCEDURE C can access only the variables of PROCEDURE A and MAIN.
4484 PROCEDURE C cannot access the variables of PROCEDURE B or PROCEDURE D.
4486 5. PROCEDURE D can access the variables of PROCEDURE C, PROCEDURE A, and
4487 MAIN. PROCEDURE D cannot access the variables of PROCEDURE B.
4489 ENTER at the beginning of the MAIN PROGRAM creates dynamic storage space
4490 for MAIN but copies no pointers. The first and only word in the display
4491 points to itself because there is no previous value for LEAVE to return to
4492 BP. See figure 4-2a.
4494 After MAIN calls PROCEDURE A, ENTER creates a new display for PROCEDURE A
4495 with the first word pointing to the previous value of BP (BPM for LEAVE to
4496 return to the MAIN stack frame) and the second word pointing to the current
4497 value of BP. Procedure A can access variables in MAIN since MAIN is at level
4498 1. Therefore the base for the dynamic storage for MAIN is at [BP-2]. All
4499 dynamic variables for MAIN will be at a fixed offset from this value. See
4502 After PROCEDURE A calls PROCEDURE B, ENTER creates a new display for
4503 PROCEDURE B with the first word pointing to the previous value of BP, the
4504 second word pointing to the value of BP for MAIN, and the third word
4505 pointing to the value of BP for A and the last word pointing to the current
4506 BP. B can access variables in A and MAIN by fetching from the display the
4507 base addresses of the respective dynamic storage areas. See figure 4-2c.
4509 After PROCEDURE B calls PROCEDURE C, ENTER creates a new display for
4510 PROCEDURE C with the first word pointing to the previous value of BP, the
4511 second word pointing to the value of BP for MAIN, and the third word
4512 pointing to the BP value for A and the third word pointing to the current
4513 value of BP. Because PROCEDURE B and PROCEDURE C have the same lexical
4514 level, PROCEDURE C is not allowed access to variables in B and therefore
4515 does not receive a pointer to the beginning of PROCEDURE B's stack frame.
4518 LEAVE (Leave Procedure) reverses the action of the previous ENTER
4519 instruction. The LEAVE instruction does not include any operands.
4522 LEAVE. First, LEAVE copies BP to SP to release all stack space allocated
4523 to the procedure by the most recent ENTER instruction. Next, LEAVE pops
4524 the old value of BP from the stack. A subsequent RET instruction can then
4525 remove any arguments that were pushed on the stack by the calling program
4526 for use by the called procedure.
4528 BOUND (Detect Value Out of Range) verifies that the signed value contained
4529 in the specified register lies within specified limits. An interrupt (INT 5)
4530 occurs if the value contained in the register is less than the lower bound
4531 or greater than the upper bound.
4533 The BOUND instruction includes two operands. The first operand specifies
4534 the register being tested. The second operand contains the effective
4535 relative address of the two signed BOUND limit values. The BOUND instruction
4536 assumes that it can obtain the upper limit from the memory word that
4537 immediately follows the lower limit. These limit values cannot be register
4538 operands; if they are, an invalid opcode exception occurs.
4540 BOUND is useful for checking array bounds before using a new index value to
4541 access an element within the array. BOUND provides a simple way to check the
4542 value of an index register before the program overwrites information in a
4543 location beyond the limit of the array.
4545 The two-word block of memory that specifies the lower and upper limits of
4546 an array might typically reside just before the array itself. This makes the
4547 array bounds accessible at a constant offset of -4 from the beginning of the
4548 array. Because the address of the array will already be present in a
4549 register, this practice avoids extra calculations to obtain the effective
4550 address of the array bounds.
4553 BOUND BX,ARRAY-4. Compares the value in BX with the lower limit at
4554 address ARRAY-4 and the upper limit at address ARRAY-2. If the signed
4555 value in BX is less than the lower bound or greater than the upper bound,
4556 the interrupt for this instruction (INT 5) occurs. Otherwise, this
4557 instruction has no effect.
4560 Figure 4-1. Formal Definition of the ENTER Instruction
4562 The Formal Definition Of The ENTER Instruction. For All Cases Is Given By
4563 The Following Listing. LEVEL Denotes The Value Of The Second Operand.
4566 Set a temporary value FRAME_PTR:=SP
4568 Repeat (LEVEL - 1) times:
4570 Push the word pointed to by BP
4575 SP:=SP - first operand.
4578 Figure 4-2. Variable Access in Nested Procedures
4580 ‚�����������������������������������������ƒ
4581 € MAIN PROGRAM (LEXICAL LEVEL 1) €
4582 € ‚�������������������������������������ƒ €
4583 € € PROCEDURE A (LEXICAL LEVEL 2) € €
4584 € € ‚�����������������������������ƒ € €
4585 € € €PROCEDURE B (LEXICAL LEVEL 3)€ € €
4586 € € „�����������������������������… € €
4588 € € ‚���������������������������������ƒ € €
4589 € € € PROCEDURE C (LEXICAL LEVEL 3) € € €
4590 € € € ‚�����������������������������ƒ € € €
4591 € € € €PROCEDURE D (LEXICAL LEVEL 4)€ € € €
4592 € € € „�����������������������������… € € €
4594 € € „���������������������������������… € €
4596 € „�������������������������������������… €
4598 „�����������������������������������������…
4601 Figure 4-2a. Stack Frame for MAIN at Level 1
4607 BP FOR MAIN‘‘
\x10†���������������‡ –‘DISPLAY
4609 BPM = BP value for MAIN € �
4616 SP‘‘
\x10†���������������‡
4620 Figure 4-2b. Stack Frame for PROCEDURE A
4634 BP FOR A‘‘
\x10†���������������‡ �
4636 †���������������‡ –‘DISPLAY
4638 BPA = BP value for PROCEDURE A € �
4644 SP‘‘
\x10†���������������‡‘•
4650 Figure 4-2c. Stack Frame for PROCEDURE B at Level 3 Called from A
4675 BP‘‘
\x10†���������������‡ �
4677 †���������������‡ –‘DISPLAY
4688 SP‘‘
\x10†���������������‡
4692 Figure 4-2d. Stack Frame for PROCEDURE C at Level 3 Called from B
4717 BP‘‘
\x10†���������������‡‘“
4728 SP‘‘
\x10†���������������‡‘•
4732 Chapter 5 Real Address Mode
4734 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
4736 The 80286 can be operated in either of two modes according to the status of
4737 the Protection Enabled bit of the MSW status register. In contrast to the
4738 "modes" and "mode bits" of some processors, however, the 80286 modes do not
4739 represent a radical transition between conflicting architectures. Instead,
4740 the setting of the Protection Enabled bit simply determines whether certain
4741 advanced features, in addition to the baseline architecture of the 80286,
4742 are to be made available to system designers and programmers.
4744 If the Protection Enabled (PE) bit is set by the programmer, the processor
4745 changes into Protected Virtual Address Mode. In this mode of operation,
4746 memory addressing is performed in terms of virtual addresses, with on-chip
4747 mapping mechanisms performing the virtual-to-physical translation. Only in
4748 this mode can the system designer make use of the advanced architectural
4749 features of the 80286: virtual memory support, system-wide protection, and
4750 built-in multitasking mechanisms are among the new features provided in this
4751 mode of operation. Refer to Part II of this book (Chapters 6, 7, 8, 9,
4752 10, and 11) for details on Protected Mode operation.
4754 Initially, upon system reset, the processor starts up in Real Address Mode.
4755 In this mode of operation, all memory addressing is performed in terms of
4756 real physical addresses. In effect, the architecture of the 80286 in
4757 this mode is identical to that of the 8086 and other processors in the 8086
4758 family. The principal features of this baseline architecture have already
4759 been discussed throughout Part I (Chapters 2, 3, and 4) of this book.
4760 This chapter discusses certain additional topics‘‘addressing, interrupt
4761 handling, and system initialization‘‘that complete the system programmer's
4762 view of the 80286 in Real Address Mode.
4765 5.1 Addressing and Segmentation
4767 Like other processors in the 8086 family, the 80286 provides a one-megabyte
4768 memory space (2^(20) bytes) when operated in Real Address Mode. Physical
4769 addresses are the 20-bit values that uniquely identify each byte location in
4770 this address space. Physical addresses, therefore, may range from 0 through
4771 FFFFFH. Address bits A20-A23 may not always be zero in Real Address Mode.
4772 A20-A23 should not be used by the system while the 80286 is operating in
4775 An address is specified by a 32-bit pointer containing two components: (1)
4776 a 16-bit effective address offset that determines the displacement, in
4777 bytes, of a particular location within a segment; and (2) a 16-bit segment
4778 selector component that determines the starting address of the segment.
4779 Both components of an address may be referenced explicitly by an instruction
4780 (such as JMP, LES, LDS, or CALL); more often, however, the segment selector
4781 is simply the contents of a segment register.
4783 The interpretation of the first component, the effective address offset, is
4784 straight-forward. Segments are at most 64K (2^(16)) bytes in length, so an
4785 unsigned 16-bit quantity is sufficient to address any arbitrary byte
4786 location with a segment. The lowest-addressed byte within a segment has an
4787 offset of 0, and the highest-addressed byte has an offset of FFFFH. Data
4788 operands must be completely contained within a segment and must be
4789 contiguous. (These rules apply in both modes.)
4791 A segment selector is the second component of a logical address. This
4792 16-bit quantity specifies the starting address of a segment within a
4793 physical address space of 2^(20) bytes.
4795 Whenever the 80286 accesses memory in Real Address Mode, it generates a
4796 20-bit physical address from a segment selector and offset value. The
4797 segment selector value is left-shifted four bit positions to form the
4798 segment base address. The offset is extended with 4 high order zeroes and
4799 added to the base to form the physical address (see figure 5-1).
4801 Therefore, every segment is required to start at a byte address that is
4802 evenly divisible by 16; thus, each segment is positioned at a 20-bit
4803 physical address whose least significant four bits are zeroes. This
4804 arrangement allows the 80286 to interpret a segment selector as the
4805 high-order 16 bits of a 20-bit segment base address.
4807 No limit or access checks are performed by the 80286 in the Real Address
4808 Mode. All segments are readable, writable, executable, and have a limit of
4809 0FFFFH (65,535 bytes). To save physical memory, you can use unused portions
4810 of a segment as another segment by overlapping the two (see figure 5-2).
4811 The Intel 8086 software development tools support this feature via the
4812 segment override and group operators. However, programs that access segment
4813 B from segment A become incompatible in the protected virtual address mode.
4816 Figure 5-1a. Forming the Segment Base Address
4818 16 BIT SEGMENT SELECTOR
4819 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
4821 ‚��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð � � � � � ƒ
4822 € � � � � � � � � � � � � � � � �0 �0 �0 �0
4823 „��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤ � � � � � …
4827 Figure 5-1b. Forming the 20-bit Physical Address in the Real Address Mode
4829 ‚��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð � � � � � ƒ
4830 SEGMENT BASE € � � � � � � � � � � � � � � � �0 �0 �0 �0
4831 „��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤ � � � � � …
4834 ‚ � � � � � Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��ƒ
4835 OFFSET 0 �0 �0 �0 � � � � � � � � � � � � � � � � €
4836 „ � � � � � ¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��…
4839 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
4840 ‚��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��ƒ
4841 PHYSICAL € � � � � � � � � � � � � � � � � � � � €
4842 ADDRESS „��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��…
4846 Figure 5-2. Overlapping Segments to Save Physical Memory
4850 Ñ ‘‘ ‘‘ ‘‘ ‘‘ ‘Î ‘‘‘
4855 ‘‘‘ Α ‘‘ ‘‘ ‘‘ ‘‘ ‘Î �
4856 \x1e € OVERLAP €
\x1f
4857 � †���������������‡
\x11‘‘‘‘‘ BASE OF
4858 SEGMENT A 64K € € SEGMENT B
4862 ‘‘‘ †���������������‡
\x11‘‘‘‘‘ BASE OF
4867 5.2 Interrupt Handling
4869 Program interrupts may be generated in either of two distinct ways. An
4870 internal interrupt is caused directly by the currently executing program.
4871 The execution of a particular instruction results in the occurrence of an
4872 interrupt, whether intentionally (e.g., an INT n instruction) or as an
4873 unanticipated exception (e.g., invalid opcode). On the other hand, an
4874 external interrupt occurs asynchronously as the result of an event
4875 external to the processor, and bears no necessary relationship with the
4876 currently executing program. The INTR and NMI pins of the 80286 provide the
4877 means by which external hardware signals the occurrence of such events.
4880 5.2.1 Interrupt Vector Table
4882 Whatever its origin, whether internal or external, an interrupt demands
4883 immediate attention from an associated service routine. Control must be
4884 transferred, at least for the moment, from the currently executing program
4885 to the appropriate interrupt service routine. By means of interrupt
4886 vectors, the 80286 handles such control transfers uniformly for both kinds
4889 An interrupt vector is an unsigned integer in the range of 0-255; every
4890 interrupt is assigned such a vector. In some cases, the assignment is
4891 predetermined and fixed: for example, an external NMI interrupt is
4892 invariably associated with vector 2, while an internal divide exception is
4893 always associated with vector 0. In most cases, however, the association of
4894 an interrupt and a vector is established dynamically. An external INTR
4895 interrupt, for example, supplies a vector in response to an interrupt
4896 acknowledge bus cycle, while the INT n instruction supplies a vector
4897 incorporated within the instruction itself. The vector is shifted two places
4898 left to form a byte address into the table (see figure 5-3).
4900 In any case, the 80286 uses the interrupt vector as an index into a table
4901 in order to determine the address of the corresponding interrupt service
4902 routine. For Real Address Mode, this table is known as the Interrupt Vector
4903 Table. Its format is illustrated in figure 5-3.
4905 The Interrupt Vector Table consists of as many as 256 consecutive entries,
4906 each four bytes long. Each entry defines the address of a service routine to
4907 be associated with the correspondingly numbered interrupt vector code.
4908 Within each entry, an address is specified by a full 32-bit pointer that
4909 consists of a 16-bit offset and a 16-bit segment selector. Interrupts 0-31
4910 are reserved by Intel.
4912 In Real Address Mode, the interrupt table can be accessed directly at
4913 physical memory location 0 through 1023. In the protected virtual address
4914 mode, however, the interrupt vector table has no fixed physical address and
4915 cannot be directly accessed. Therefore, Real Address mode programs that
4916 directly manipulate the interrupt vector table will not work in the
4917 protected virtual address mode.
4920 Table 5-1. Interrupt Processing Order
4923 1. Instruction exception
4926 4. Processor extension segment overrun
4930 Figure 5-3. Interrupt Vector Table for Real Address Mode
4933 INTERRUPT HANDLER PHYSICAL
4937 INTERRUPT 255 € POINTER € 1020
4939 INTERRUPT 254 € POINTER € 1018
4941 INTERRUPT 253 € POINTER €
\x11“ 1012
4942 †���������������‡ ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
4943 € € ‚�����������������Ф�����������Ð�Ð�ƒ
4944 € € €0 ¨ ¨ ¨ ¨ ¨ ¨ ¨ 0� VECTOR �0�0€
4945 ¸ ¸ „�����������������¤������������¤�¤�…
4949 INTERRUPT 1 € POINTER € 4
4951 INTERRUPT 0 € POINTER € 0
4955 5.2.1.1 Interrupt Priorities
4957 When simultaneous interrupt requests occur, they are processed in a fixed
4958 order as shown in table 5-1. Interrupt processing involves saving the
4959 flags, the return address, and setting CS:IP to point at the first
4960 instruction of the interrupt handler. If other interrupts remain enabled,
4961 they are processed before the first instruction of the current interrupt
4962 handler is executed. The last interrupt processed is therefore the first one
4966 5.2.2 Interrupt Procedures
4968 When an interrupt occurs in Real Address Mode, the 8086 performs the
4969 following sequence of steps. First, the FLAGS register, as well as the old
4970 values of CS and IP, are pushed onto the stack (see figure 5-4). The IF and
4971 TF flag bits are cleared. The vector number is then used to read the
4972 address of the interrupt service routine from the interrupt table. Execution
4973 begins at this address.
4975 Thus, when control is passed to an interrupt service routine, the return
4976 linkage is placed on the stack, interrupts are disabled, and single-step
4977 trace (if in effect) is turned off. The IRET instruction at the end of the
4978 interrupt service routine will reverse these steps before transferring
4979 control to the program that was interrupted.
4981 An interrupt service routine may affect registers other than other IP, CS,
4982 and FLAGS. It is the responsibility of an interrupt routine to save
4983 additional context information before proceeding so that the state of the
4984 machine can be restored upon completion of the interrupt service routine
4985 (PUSHA and POPA instructions are intended for these operations). Finally,
4986 execution of the IRET instruction pops the old IP, CS, and FLAGS from the
4987 stack and resumes the execution of the interrupted program.
4990 Figure 5-4. Stack Structure after Interrupt (Real Address Mode)
4994 \x1e †���������������‡
4996 INCREASING � †���������������‡
4997 ADDRESSES � € OLD CS €
4999 � € OLD IP €
\x11‘‘ <SS:SP>
5006 5.2.3 Reserved and Dedicated Interrupt Vectors
5008 In general, the system designer is free to use almost any interrupt vectors
5009 for any given purpose. Some of the lowest-numbered vectors, however, are
5010 reserved by Intel for dedicated functions; their use is specifically implied
5011 by certain types of exceptions. None of the first 32 vectors should be
5012 defined by the user; these vectors are either invoked by pre-defined
5013 exceptions or reserved by Intel for future expansion. Table 5-2 shows the
5014 dedicated and reserved vectors of the 80286 in Real Address Mode.
5016 The purpose and function of the dedicated interrupt vectors may be
5017 summarized as follows (the saved value of CS:IP will include all leading
5020 Ž Divide error (Interrupt 0). This exception will occur if the quotient
5021 is too large or an attempt is made to divide by zero using either the
5022 DIV or IDIV instruction. The saved CS:IP points at the first byte of
5023 the failing instruction. DX and AX are unchanged.
5025 Ž Single-Step (Interrupt 1). This interrupt will occur after
5026 each instruction if the Trap Flag (TF) bit of the FLAGS register is
5027 set. Of course, TF is cleared upon entry to this or any other interrupt
5028 to prevent infinite recursion. The saved value of CS:IP will point to
5029 the next instruction.
5031 Ž Nonmaskable (Interrupt 2). This interrupt will occur upon receipt of
5032 an external signal on the NMI pin. Typically, the nonmaskable interrupt
5033 is used to implement power-fail/auto-restart procedures. The saved
5034 value of CS:IP will point to the first byte of the interrupted
5037 Ž Breakpoint (Interrupt 3). Execution of the one-byte breakpoint
5038 instruction causes this interrupt to occur. This instruction is useful
5039 for the implementation of software debuggers since it requires only one
5040 code byte and can be substituted for any instruction opcode byte. The
5041 saved value of CS:IP will point to the next instruction.
5043 Ž INTO Detected Overflow (Interrupt 4). Execution of the INTO
5044 conditional software interrupt instruction will cause this interrupt
5045 to occur if the overflow bit (OF) of the FLAGS register is set. The
5046 saved value of CS:IP will point to the next instruction.
5048 Ž BOUND Range Exceeded (Interrupt 5). Execution of the BOUND instruction
5049 will cause this interrupt to occur if the specified array index is
5050 found to be invalid with respect to the given array bounds. The saved
5051 value of CS:IP will point to the first byte of the BOUND instruction.
5053 Ž Invalid Opcode (Interrupt 6). This exception will occur if execution
5054 of an invalid opcode is attempted. (In Real Address Mode, most of the
5055 Protected Virtual Address Mode instructions are classified as invalid
5056 and should not be used). This interrupt can also occur if the
5057 effective address given by certain instructions, notably BOUND, LDS,
5058 LES, and LIDT, specifies a register rather than a memory location. The
5059 saved value of CS:IP will point to the first byte of the
5060 invalid instruction or opcode.
5062 Ž Processor Extension Not Available (Interrupt 7). Execution of the ESC
5063 instruction will cause this interrupt to occur if the status bits of
5064 the MSW indicate that processor extension functions are to be emulated
5065 in software. Refer to section 10.2.1 for more details. The saved value
5066 of CS:IP will point to the first byte of the ESC or the WAIT
5069 Ž Interrupt Table Limit Too Small (Interrupt 8). This interrupt will
5070 occur if the limit of the interrupt vector table was changed from 3FFH
5071 by the LIDT instruction and an interrupt whose vector is outside the
5072 limit occurs. The saved value of CS:IP will point to the first byte of
5073 the instruction that caused the interrupt or that was ready to execute
5074 before an external interrupt occurred. No error code is pushed.
5076 Ž Processor Extension Segment Overrun Interrupt (Interrupt 9). The
5077 interrupt will occur if a processor extension memory operand does not
5078 fit in a segment. The saved CS:IP will point at the first byte of the
5079 instruction that caused the interrupt.
5081 Ž Segment Overrun Exception (Interrupt 13). This interrupt will occur if
5082 a memory operand does not fit in a segment. In Real Mode this will
5083 occur only when a word operand begins at segment offset 0FFFFH. The
5084 saved CS:IP will point at the first byte of the instruction that
5085 caused the interrupt. No error code is pushed.
5087 Ž Processor Extension Error (Interrupt 16). This interrupt occurs after
5088 the numeric instruction that caused the error. It can only occur while
5089 executing a subsequent WAIT or ESC. The saved value of CS:IP will point
5090 to the first byte of the ESC or the WAIT instruction. The address of
5091 the failed numeric instruction is saved in the NPX.
5094 Table 5-2. Dedicated and Reserved Interrupt Vectors in Real Address Mode
5097 Function Interrupt Related Instructions Return Address
5098 Number Before Instruction
5100 Divide error exception 0 DIV, IDIV Yes
5101 Single step interrupt 1 All N/A
5102 NMI interrupt 2 All N/A
5103 Breakpoint interrupt 3 INT N/A
5104 INTO detected overflow 4 INTO No
5106 BOUND range exceeded 5 BOUND Yes
5108 Invalid opcode exception 6 Any undefined opcode Yes
5109 Processor extension 7 ESC or WAIT Yes
5110 not available exception
5111 Interrupt table 8 LIDT Yes
5113 Processor extension 9 ESC Yes
5114 segment overrun interrupt
5115 Segment overrun exception 13 Any memory reference Yes
5117 attempts to reference
5122 Processor extension 16 ESC or WAIT N/A
5127 N/A = Not Applicable
5130 5.3 System Initialization
5132 The 80286 provides an orderly way to start or restart an executing system.
5133 Upon receipt of the RESET signal, certain processor registers go into the
5134 determinate state shown in table 5-3.
5136 Since the CS register contains F000 (thus specifying a code segment
5137 starting at physical address F0000) and the instruction pointer contains
5138 FFF0, the processor will execute its first instruction at physical address
5139 FFFF0H. The uppermost 16 bytes of physical memory are therefore reserved
5140 for initial startup logic. Ordinarily, this location contains an
5141 intersegment direct JMP instruction whose target is the actual beginning of
5142 a system initialization or restart program.
5144 Some of the steps normally performed by a system initialization routine are
5149 Ž Load programs and data from secondary storage into memory.
5151 Ž Initialize external devices.
5153 Ž Enable interrupts (i.e., set the IF bit of the FLAGS register). Set
5154 any other desired FLAGS bit as well.
5156 Ž Set the appropriate MSW flags if a processor extension is present, or
5157 if processor extension functions are to be emulated by software.
5159 Ž Set other registers, as appropriate, to the desired initial values.
5161 Ž Execute. (Ordinarily, this last step is performed as an intersegment
5162 JMP to the main system program.)
5165 Table 5-3. Processor State after RESET
5177 Chapter 6 Memory Management and Virtual Addressing
5179 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
5181 In Protected Virtual Address Mode, the 80286 provides an advanced
5182 architecture that retains substantial compatibility with the 8086 and other
5183 processors in the 8086 family. In many respects, the baseline architecture
5184 of the processor remains constant regardless of the mode of operation.
5185 Application programmers continue to use the same set of instructions,
5186 addressing modes, and data types in Protected Mode as in Real Address Mode.
5188 The major difference between the two modes of operation is that the
5189 Protected Mode provides system programmers with additional architectural
5190 features, supplementary to the baseline architecture, that can be used to
5191 good advantage in the design and implementation of advanced systems.
5192 Especially noteworthy are the mechanisms provided for memory management,
5193 protection, and multitasking.
5195 This chapter focuses on the memory management mechanisms of Protected Mode;
5196 the concept of a virtual address and the process of virtual-to-physical
5197 address translation are described in detail in this chapter. Subsequent
5198 chapters deal with other key aspects of Protected Mode operation. Chapter 7
5199 discusses the issue of protection and the integrated mechanisms that
5200 support a system-wide protection policy. Chapter 8 discusses the notion of
5201 a task and its central role in the 80286 architecture. Chapters 9, 10, and
5202 11 discuss certain additional topics‘‘interrupt handling, special
5203 instructions, system initialization, etc.‘‘that complete the system
5204 programmer's view of 80286 Protected Mode.
5207 6.1 Memory Management Overview
5209 A memory management scheme interposes a mapping operation between logical
5210 addresses (i.e., addresses as they are viewed by programs) and physical
5211 addresses (i.e., actual addresses in real memory). Since the logical address
5212 spaces are independent of physical memory (dynamically relocatable), the
5213 mapping (the assignment of real address space to virtual address space) is
5214 transparent to software. This allows the program development tools (for
5215 static systems) or the system software (for reprogrammable systems) to
5216 control the allocation of space in real memory without regard to the
5217 specifics of individual programs.
5219 Application programs may be translated and loaded independently since they
5220 deal strictly with virtual addresses. Any program can be relocated to use
5221 any available segments of physical memory.
5223 The 80286, when operated in Protected Mode, provides an efficient on-chip
5224 memory management architecture. Moreover, as described in Chapter 11, the
5225 80286 also supports the implementation of virtual memory systems‘‘that is,
5226 systems that dynamically swap chunks of code and data between real memory
5227 and secondary storage devices (e.g., a disk) independent of and transparent
5228 to the executing application programs. Thus, a program-visible address is
5229 more aptly termed a virtual address rather than a logical address since it
5230 may actually refer to a location not currently present in real memory.
5232 Memory management, then, consists of a mechanism for mapping the virtual
5233 addresses that are visible to the program onto the physical addresses of
5234 real memory. With the 80286, segmentation is the key to virtual memory
5235 addressing. Virtual memory is partitioned into a number of individual
5236 segments, which are the units of memory that are mapped into physical memory
5237 and swapped to and from secondary storage devices. Most of this chapter is
5238 devoted to a detailed discussion of the mapping and virtual memory
5239 mechanisms of the 80286.
5241 The concept of a task also plays a significant role in memory management
5242 since distinct memory mappings may be assigned to the different tasks in a
5243 multitask or multi-user environment. A complete discussion of tasks is
5244 deferred until Chapter 8, "Tasks and State Transition." For present
5245 purposes, it is sufficient to think of a task as an ongoing process, or
5246 execution path, that is dedicated to a particular function. In a multi-user
5247 time-sharing environment, for example, the processing required to interact
5248 with a particular user may be considered as a single task, functionally
5249 independent of the other tasks (i.e., users) in the system.
5252 6.2 Virtual Addresses
5254 In Protected Mode, application programs deal exclusively with virtual
5255 addresses; programs have no access whatsoever to the actual physical
5256 addresses generated by the processor. As discussed in Chapter 2, an address
5257 is specified by a program in terms of two components: (1) a 16-bit
5258 effective address offset that determines the displacement, in bytes, of a
5259 location within a segment; and (2) a 16-bit segment selector that uniquely
5260 references a particular segment. Jointly, these two components constitute a
5261 complete 32-bit address (pointer data type), as shown in figure 6-1.
5263 These 32-bit virtual addresses are manipulated by programs in exactly the
5264 same way as the two-component addresses of Real Address Mode. After a
5265 program loads the segment selector component of an address into a segment
5266 register, each subsequent reference to locations within the selected
5267 segment requires only a 16-bit offset be specified. Locality of reference
5268 will ordinarily insure that addresses can be specified very efficiently
5269 using only 16-bit offsets.
5271 An important difference between Real Address Mode and Protected Mode,
5272 however, concerns the actual format and information content of segment
5273 selectors. In Real Address Mode, as with the 8086 and other processors in
5274 the 8086 family, a 16-bit selector is merely the upper bits of a segment's
5275 physical base address. By contrast, segment selectors in Protected Mode
5276 follow an entirely different format, as illustrated by figure 6-1.
5278 Two of the selector bits, designated as the RPL field in figure 6-1, are
5279 not actually involved in the selection and specification of segments; their
5280 use is discussed in Chapter 7.
5282 The remaining 14 bits of the selector component uniquely designate a
5283 particular segment. The virtual address space of a program, therefore, may
5284 encompass as many as 16,384 (2^(14)) distinct segments. Segments themselves
5285 are of variable size, ranging from as small as a single byte to as large as
5286 64K (2^(16)) bytes. Thus, a program's virtual address space may contain,
5287 altogether, up to a full gigabyte (2^(30) = 2^(14) * 2^(16)) of individually
5288 addressable byte locations.
5290 The entirety of a program's virtual address space is further subdivided
5291 into two separate halves, as distinguished by the TI ("table indicator") bit
5292 in the virtual address. These two halves are the global address space and
5293 the local address space.
5295 The global address space is used for system-wide data and procedures
5296 including operating system software, library routines, runtime language
5297 support and other commonly shared system services. (To application programs,
5298 the operating system appears to be a set of service routines that are
5299 accessible to all tasks.) Global space is shared by all tasks to avoid
5300 unnecessary replication of system service routines and to facilitate shared
5301 data and interrupt handling. Global address space is defined by addresses
5302 with a zero in the TI bit position; it is identically mapped for all tasks
5305 The other half of the virtual address space‘‘comprising those addresses
5306 with the TI bit set‘‘is separately mapped for each task in the system.
5307 Because such an address space is local to the task for which it is defined,
5308 it is referred to as a local address space. In general, code and data
5309 segments within a task's local address space are private to that particular
5310 task or user. Figure 6-2 illustrates the task isolation made possible by
5311 partitioning the virtual address spaces into local and global regions.
5313 Within each of the two regions addressable by a program‘‘either the global
5314 address space or a particular local address space‘‘as many as 8,192 (2^(13))
5315 distinct segments may be defined. The INDEX field of the segment selector
5316 allows for a unique specification of each of these segments. This 13-bit
5317 quantity acts as an index into a memory-resident table, called a descriptor
5318 table, that records the mapping between segment address and the physical
5319 locations allocated to each distinct segment. (These descriptor tables, and
5320 their role in virtual-to-physical address translation, are described in the
5321 sections that follow.)
5323 In summary, a Protected Mode virtual address is a 32-bit pointer to a
5324 particular byte location within a one-gigabyte virtual address space. Each
5325 such pointer consists of a 16-bit selector component and a 16-bit offset
5326 component. The selector component, in turn, comprises a 13-bit table index,
5327 a 1-bit table indicator (local versus global), and a 2-bit RPL field; all
5328 but this last field serve to select a particular segment from among the 16K
5329 segments in a task's virtual address space. The offset component of a full
5330 pointer is an unsigned 16-bit integer that specifies the desired byte
5331 location within the selected segment.
5334 Figure 6-1. Format of the Segment Selector Component
5337 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
5339 ‚��������������������Ð��������������������ƒ
5340 € SEGMENT SELECTOR � SEGMENT OFFSET €
5341 „��������������������¤��������������������…
5345 ’‘‘• ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
5347 ‚��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��Ð��ƒ
5349 „��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��¤��…
5350 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
5354 Figure 6-2. Address Spaces and Task Isolation
5360 TASK 3 � €ADDRESS € �
5361 VIRTUAL ADDRESS SPACE “ � €SPACE € �
\x11‘‘‘‘TASK 1
5362 \x1f � „����������… � VIRTUAL ADDRESS SPACE
5363 ’‘‘‘‘‘‘‘‘‘‘‘‘‘�‘‘‘‘‘‘‘‘‘‘‘‘‘‘�“
5364 � ‚����������ƒ�’‘‘‘‘‘‘‘‘‘‘‘‘‘�‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
5365 � €TASK 3 €�� ‚��������ƒ �� ‚����������ƒ �
5366 � €LOCAL €�� €GLOBAL € �� €TASK 2 € �
5367 � €ADDRESS €�� €ADDRESS € �� €LOCAL € �
5368 � €SPACE €�� €SPACE € �� €ADDRESS € �
5369 � „����������…�� „��������… �� €SPACE € �
5370 ”‘‘‘‘‘‘‘‘‘‘‘‘‘”‘‘‘‘‘‘‘‘‘‘‘‘‘‘•• „����������… �
5371 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
5374 VIRTUAL ADDRESS SPACE
5377 6.3 Descriptor Tables
5379 A descriptor table is a memory-resident table either defined by program
5380 development tools in a static system or controlled by operating system
5381 software in systems that are reprogrammable. The descriptor table contents
5382 govern the interpretation of virtual addresses. Whenever the 80286 decodes
5383 a virtual address, translating a full 32-bit pointer into a corresponding
5384 24-bit physical address, it implicitly references one of these tables.
5386 Within a Protected Mode system, there are ordinarily several descriptor
5387 tables resident in memory. One of these is the global descriptor table
5388 (GDT); this table provides a complete description of the global address
5389 space. In addition, there may be one or more local descriptor tables
5390 (LDTs), each describing the local address space of one or more tasks.
5392 For each task in the system, a pair of descriptor tables‘‘consisting of the
5393 GDT (shared by all tasks) and a particular LDT (private to the task or to a
5394 group of closely related tasks)‘‘provides a complete description of that
5395 task's virtual address space. The protection mechanism described in Chapter
5396 7, "Protection," ensures that a task is granted access only to its own
5397 virtual address space. In the simplest of system configurations, tasks can
5398 reside entirely within the GDT without the use of local descriptor tables.
5399 This will simplify system software by only requiring maintenance of one
5400 table (the GDT) at the expense of no isolation between tasks. The point is:
5401 the 80286 memory management scheme is flexible enough to accommodate a
5402 variety of implementations and does not require use of all possible
5403 facilities when implementing a system.
5405 The descriptor tables consist of a sequence of 8-byte entries called
5406 descriptors. A descriptor table may contain from 1 to 8192 entries.
5408 Within a descriptor table, two main classes of descriptors are recognized
5409 by the 80286 architecture. The most important of these, from the standpoint
5410 of memory management, are called segment descriptors; these determine the
5411 set of segments that are included within a given address space. The other
5412 class are special-purpose control descriptors‘‘such as call gates and task
5413 descriptors‘‘to implement protection (described in succeeding chapters) and
5414 special system data segments.
5416 Figure 6-3 shows the format of a segment descriptor. Note that it provides
5417 information about the physical-memory base address and size of a segment, as
5418 well as certain access information. If a particular segment is to be
5419 included within a virtual address space, then a segment descriptor that
5420 describes that segment must be included within the appropriate descriptor
5421 table. Thus, within the GDT, there are segment descriptors for all of the
5422 segments that comprise a system's global address space. Similarly, within a
5423 task's LDT, there must be a descriptor for each of the segments that are to
5424 be included in that task's local address space.
5426 Each local descriptor table is itself a special system segment,
5427 recognizable as such by the 80286 architecture and described by a specific
5428 type of segment descriptor (see figure 6-4). Because there is only a single
5429 GDT segment, it is not defined by a segment descriptor. Its base and size
5430 information is maintained in a dedicated register, GDTR, as described below
5433 Similarly, there is another dedicated register within the 80286, LDTR, that
5434 records the base and size of the current LDT segment (i.e., the LDT
5435 associated with the currently executing task). The LDTR register state,
5436 however, is volatile: its contents are automatically altered whenever a
5437 task switch is made from one task to another. An alternate specification
5438 independent of changeable register contents must therefore exist for each
5439 LDT in the system. This independent specification is accomplished by means
5440 of special system segment descriptors known as descriptor table descriptors
5443 Figure 6-4 shows the format of a descriptor table descriptor. (Note that it
5444 is distinguished from an ordinary segment descriptor by the contents of
5445 certain bits in the access byte.) This special type of descriptor is used to
5446 specify the physical base address and size of a local descriptor table that
5447 defines the virtual address space and address mapping for an individual user
5448 or task (figure 6-5).
5450 Each LDT segment in a system must lie within that system's global address
5451 space. Thus, all of the descriptor table descriptors must be included among
5452 the entries in the global descriptor table (the GDT) of a system. In fact,
5453 these special descriptors may appear only in the GDT. Reference to an LDT
5454 descriptor within an LDT will cause a protection violation. Even though
5455 they are in the global address space available to all tasks, the descriptor
5456 table descriptors are protected from corruption within the GDT since they
5457 are special system segments and can only be accessed for loading into the
5461 Figure 6-3. Segment Descriptors (S=1)
5464 ‚�������������������������������Ð��������������������������������ƒ
5466 Must be set to 0 for compatibility with iAPX 386 MUST BE 0 €+6
5467 ACCESS Ñ‘‘˜‘‘‘‘‘‘‘˜‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘˜‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
5468 +5€ P � DPL �S=1� TYPE � A � BASE{23-16} €+4
5469 RIGHTS Ñ‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
5471 BYTES Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
5473 „�������������������������������¤��������������������������������…
5476 ACCESS RIGHTS BYTES:
5478 DPL = DESCRIPTOR PRIVILEGE LEVEL
5479 S = SEGMENT DESCRIPTOR
5480 TYPE = SEGMENT TYPE AND ACCESS INFORMATION
5485 Figure 6-4. Special Purpose Descriptors or System Segment Descriptors (S=1)
5488 ‚�������������������������������Ð��������������������������������ƒ
5490 Must be set to 0 for compatibility with iAPX 386 MUST BE 0 €+6
5491 Ñ‘‘˜‘‘‘‘‘‘‘˜‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
5492 +5€ P � DPL �S=1� TYPE � BASE{23-16} €+4
5493 Ñ‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
5495 €‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘€
5497 „�������������������������������¤��������������������������������…
5500 ACCESS RIGHTS BYTES:
5502 DPL = DESCRIPTOR PRIVILEGE LEVEL
5503 S = SEGMENT DESCRIPTOR
5504 TYPE = SEGMENT TYPE AND ACCESS INFORMATION
5505 (Includes control and system segments)
5507 0 = INVALID DESCRIPTOR
5508 1 = AVAILABLE TASK STATE SEGMENT
5510 3 = BUSY TASK STATE SEGMENT
5511 4-7 = CONTROL DESCRIPTOR (see Chapter 7)
5512 8 = INVALID DESCRIPTOR (reserved by Intel)
5513 9-F = RESERVED BY INTEL
5515 Figure 6-5. LDT Descriptors
5519 ’‘
\x10€ € ’‘
\x10†���������������‡
5521 \a \a � € € � € ONE €
5522 € € � †�����������������‡ � € SEGMENT €
5523 †�����������������‡ � € RESERVED ZERO € � € OF THE €SEGMENT
5524 € RESERVED ZERO € � †��������Ð��������‡“ � € TASKS €LIMIT
5525 †��������Ð��������‡“ � € �BASE{23-16} � € LOCAL €
5526 € �BASE{23-16} � †��������¤��������‡–‘“ � € (private) €
5527 †��������¤��������‡–‘“ � € BASE{15-0} €� � � € ADDRESS €
5528 € BASE{15-0} €� � � †�����������������‡• � � € SPACE €
5529 †�����������������‡• � � € BASE{15-0} Ñ‘�‘• € €
5530 € LIMIT{15-0} Ñ‘�‘• †�����������������‡ ”‘‘‘
\x10†���������������‡SEGMENT
5531 †�����������������‡ � € € € €BASE
5533 \a DESCRIPTION IN
\a � € € € €
5534 THE GDT IN MEMORY � †�����������������‡ € €
5537 ”‘‘‘
\x10†�����������������‡ € €
5538 € DESCRIPTOR € € SEGMENT €
5539 \a TABLES IN RAM
\a \a IN RAM
\a
5542 6.4 Virtual-to-Physical Address Translation
5544 The translation of a full 32-bit virtual address pointer into a real 24-bit
5545 physical address is shown by figure 6-6. When the segment's base address is
5546 determined as a result of the mapping process, the offset value is added to
5547 the result to obtain the physical address.
5549 The actual mapping is performed on the selector component of the virtual
5550 address. The 16-bit segment selector is mapped to a 24-bit segment base
5551 address via a segment descriptor maintained in one of the descriptor tables.
5553 The TI bit in the segment selector (see figure 6-1) determines which of two
5554 descriptor tables, either the GDT or the current LDT, is to be chosen for
5555 memory mapping. In either case, using the GDTR or LDTR register, the
5556 processor can readily determine the physical base address of the
5557 memory-resident table.
5559 The INDEX field in the segment selector specifies a particular descriptor
5560 entry within the chosen table. The processor simply multiplies this index
5561 value by 8 (the length of a descriptor), and adds the result to the base
5562 address of the descriptor table in order to access the appropriate segment
5563 descriptor in the table.
5565 Finally, the segment descriptor contains the physical base address of the
5566 target segment, as well as size (limit) and access information. The
5567 processor sums the 24-bit segment base and the specified 16-bit offset to
5568 generate the resulting 24-bit physical address.
5571 Figure 6-6. Virtual-to-Physical Address Translation
5573 ‚�����������������������������������������������������ƒ
5575 € ‚������������������������Ð������������������������ƒ €
\a TARGET
\a
5576 € € SELECTOR � OFFSET € € € SEGMENT €
5577 € „����Ð�����������Ð�������¤�����Ð������������������… € € €
5578 „�����������������������������������������������������… € €
5581 �
\x1f €+Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10€ DATUM €
5582 � DESCRIPTOR „�… PHYSICAL ADDRESS Ñ‘‘‘‘‘‘‘‘Â
5583 �
\a TABLE
\a \x1e € €
5584 � †������������‡ � € €
5586 � Ñ‘‘‘‘‘‘‘‘‘‘‘ � € €
5587 � € SEGMENT € � SEGMENT BASE € €
5588 \x1f € DESCRIPTOR Ñ‘‘‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10†���������‡
5589 ‘ ‘ ‘ ‘ ‘ ‘ Α‘‘‘‘‘‘‘‘‘‘‘ € €
5590 INDEX
\x1e ¸ ¸
\a \a
5591 ‘ ‘ ‘ ™ ‘ ‘ Î������������‡
5595 6.5 Segments and Segment Descriptors
5597 Segments are the basic units of 80286 memory management. In contrast to
5598 schemes based on fixed-size pages, segmentation allows for a very efficient
5599 implementation of software: variable-length segments can be tailored to the
5600 exact requirements of an application. Segmentation, moreover, is consistent
5601 with the way a programmer naturally deals with his virtual address space:
5602 programmers are encouraged to divide code and data into clearly defined
5603 modules and structures which are manipulated as consistent entities. This
5604 reduces (minimizes) the potential for virtual memory thrashing.
5605 Segmentation also eliminates the restrictions on data structures that span a
5606 page (e.g., a word that crosses page boundaries).
5608 Each segment within an 80286 system is defined by an associated segment
5609 descriptor, which may appear in one or more descriptor tables. Its inclusion
5610 within a descriptor table represents the presence of its associated segment
5611 within the virtual address space defined by that table. Conversely, its
5612 ommission from a descriptor table means that the segment is absent from the
5613 corresponding address space.
5615 As shown previously in figure 6-3, an 8-byte segment descriptor encodes the
5616 following information about a particular segment:
5618 Ž Size. This 16-bit field, comprising bytes 0 and 1 of a segment
5619 descriptor, specifies an unsigned integer as the size, in bytes (from 1
5620 byte to 64K bytes), of the segment.
5622 Unlike segments in the 8086 (or the 80286 in Real Address Mode)‘‘which
5623 are never explicitly limited to less than a full 64K bytes‘‘Protected
5624 Mode segments are always assigned a specific size value. In conjunction
5625 with the protection features described in Chapter 7, this assigned
5626 size allows the enforcement of a very desirable and natural rule:
5627 inadvertent accesses to locations beyond a segment's actual boundaries
5630 Ž Base. This 24-bit field, comprising bytes 2 through 4 of a segment
5631 descriptor, specifies the physical base address of the segment; it thus
5632 defines the actual location of the segment within the 16-megabyte real
5633 memory space. The base may be any byte address within the 16-megabyte
5636 Ž Access. This 8-bit field comprises byte 5 of a segment descriptor.
5637 This access byte specifies a variety of additional information about a
5638 segment, particularly in regard to the protection features of the
5639 80286. For example, code segments are distinguished from data
5640 segments; and certain special access restrictions (such as Execute-Only
5641 or Read-Only) may be defined for segments of each type. Access byte
5642 values of 00H or 80H will always denote "invalid."
5644 Figure 6-7 shows the access byte format for both code and data segment
5645 descriptors. Detailed discussion of the protection related fields within an
5646 access byte (Conforming, Execute-Only, Descriptor Privilege Level, Expand
5647 Down, and Write-Permitted), and their use in implementing protection
5648 policies, is deferred to Chapter 7. The two fields Accessed and Present are
5649 used for virtual memory implementations.
5652 Figure 6-7. Segment Descriptor Access Bytes
5655 MSB ’‘‘‘‘‘™‘‘‘‘‘“LSB
5656 ‚���Ð�����Ð���Ð���Ð���Ð���Ð���ƒ
5657 € P � DPL � 1 � 1 � C � R � A €
5658 „���¤�����¤���¤���¤���¤���¤���…
5659 \x1e ”‘‘˜‘‘•
\x1e \x1e \x1e \x1e \x1e
5660 PRESENT (1 = yes)‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
\x1e � � � � �
5661 DESCRIPTOR PRIVILEGE LEVEL‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � � � � �
5662 (indicates segment descriptor)‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � � � �
5663 EXECUTABLE (1 = yes for code)‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � � �
5664 CONFORMING (1 = yes)‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � �
5665 READABLE (1 = yes)‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• �
5666 ACCESSED (1 = yes)‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
5668 DATA OR STACK SEGMENT
5670 ‚���Ð�����Ð���Ð���Ð����Ð���Ð���ƒ
5671 € P � DPL � 1 � 0 � ED � W � A €
5672 „���¤�����¤���¤���¤����¤���¤���…
5673 \x1e \x1e \x1e \x1e \x1e \x1e \x1e
5674 PRESENT (1 = yes)‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � � � � � �
5675 DESCRIPTOR PRIVILEGE LEVEL‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � � � � �
5676 (indicates segment descriptor)‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � � � �
5677 EXECUTABLE (0 = no for data) ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � � �
5678 CONFORMING (1 = yes)‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � �
5679 WRITEABLE (1 = yes)‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• �
5680 ACCESSED (1 = yes)‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
5683 6.6 Memory Management Registers
5685 The Protected Virtual Address Mode features of the 80286 operate at high
5686 performance due to extensions to the basic 8086 register set. Figure 6-8
5687 illustrates that portion of the extended register structure that pertains to
5688 memory management. (For a complete summary of all Protected Mode registers,
5689 refer to section 10.1).
5692 6.6.1 Segment Address Translation Registers
5694 Figure 6-8 shows the segment registers CS, DS, ES, and SS. In contrast to
5695 their usual representation, however, these registers are now depicted as
5696 64-bit registers, each with "visible" and "hidden" components.
5698 The visible portions of these segment address translation registers are
5699 manipulated by programs exactly as if they were simply the 16-bit segment
5700 registers of Real Address Mode. By loading a segment selector into one of
5701 these registers, the program makes the associated segment one of its four
5702 currently addressable segments.
5704 The operations that load these registers‘‘or, more exactly, those that load
5705 the visible portion of these registers‘‘are normal program instructions.
5706 These instructions may be divided into two categories:
5708 1. Direct segment-register load instructions. These instructions (such
5709 as LDS, LES, MOV, POP, etc.) can explicitly reference the SS, DS, or
5710 ES segment registers as the destination operand.
5712 2. Implied segment-register load instructions. These instructions (such
5713 as intersegment CALL and JMP) implicitly reference the CS code segment
5714 register; as a result of these operations, the contents of CS are
5717 Using these instructions, a program loads the visible part of the segment
5718 register with a 16-bit selector (i.e., the high-order word of a virtual
5719 address pointer). Whenever this is done, the processor automatically uses
5720 the selector to reference the appropriate descriptor and loads the 48-bit
5721 hidden descriptor cache for that segment register.
5723 The correspondence between selectors and descriptors has already been
5724 described. Remember that the selector's TI bit indicates one of the two
5725 descriptor tables, either the LDT or the GDT. Within the indicated table, a
5726 particular entry is chosen by the selector's 13-bit INDEX field. This
5727 index, scaled by a factor of 8, represents the relative displacement of the
5728 chosen table entry (a descriptor).
5730 Thus, so long as a particular selector value is valid (i.e., it points to a
5731 valid segment descriptor within the bounds of the descriptor table), it can
5732 be readily associated with an 8-byte descriptor. When a selector value is
5733 loaded into the visible part of a segment register, the 80286 automatically
5734 loads 6 bytes of the associated descriptor into the hidden part of the
5735 register. These 6 bytes, therefore, contain the size, base, and access type
5736 of the selected segment. Figure 6-9 illustrates this transparent process of
5739 In effect, the hidden descriptor fields of the segment registers function
5740 as the memory management cache of the 80286. All the information required to
5741 address the current working set of segments‘‘that is, the base address,
5742 size, and access rights of the currently addressable segments‘‘is stored in
5743 this memory cache. Unlike the probabilistic caches of other architectures,
5744 however, the 80286 cache is completely deterministic: the caching of
5745 descriptors is explicitly controlled by the program.
5747 Most memory references do not require the translation of a full 32-bit
5748 virtual address, or long pointer. Operands that are located within one of
5749 the currently addressable segments, as determined by the four segment
5750 registers, can be referenced very efficiently by means of a short pointer,
5751 which is simply a 16-bit offset.
5753 In fact, most 80286 instructions reference memory locations in precisely
5754 this way, specifying only a 16-bit offset with respect to one of the
5755 currently addressable segments. The choice of segments (CS, DS, ES, or SS)
5756 is either implicit within the instruction itself, or explicitly specified
5757 by means of a segment-override prefix (as described in Chapter 2).
5759 Thus, in most cases, virtual-to-physical address translation is actually
5760 performed in two separate steps. First, when a program loads a new value
5761 into a segment register, the processor immediately performs a mapping
5762 operation; the physical base address of the selected segment (as well as
5763 certain additional information) is automatically loaded into the hidden
5764 portion of the register. The internal cache registers (virtual address
5765 translation hardware) are therefore dynamically shared among the 16K
5766 different segments potentially addressable within the user's virtual address
5767 space. No software overhead (either system or application) is required to
5768 perform this operation.
5770 Subsequently, as the program utilizes a short pointer to reference a
5771 location within a segment, the processor generates a 24-bit physical address
5772 simply by adding the specified offset value to the previously cached segment
5773 base address. By encouraging the use of short pointers in this way, rather
5774 than requiring a full 32-bit virtual address for every memory reference, the
5775 80286 provides a very efficient on-chip mechanism for address translation,
5776 with minimum overhead for references to memory-based tables or the need for
5777 external address-translation devices.
5780 Figure 6-8. Memory Management Registers
5782 SEGMENT ADDRESS TRANSLATION REGISTERS
5784 16-BIT 48-BIT HIDDEN DESCRIPTOR CACHE
5785 SELECTOR (PROGRAM INVISIBLE‘‘LOADED BY CPU)
5786 ‚���������Ð������Ð������������������Ð��������������ƒ
5787 CS€ � � � €CODE SEGMENT REGISTER
5788 Ñ‘‘‘‘‘‘‘‘š‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
5789 DS€ � � � €DATA SEGMENT REGISTER
5790 Ñ‘‘‘‘‘‘‘‘š‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
5791 ES€ � � � €EXTRA SEGMENT REGISTER
5792 Ñ‘‘‘‘‘‘‘‘š‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
5793 SS€ � � � €STACK SEGMENT REGISTER
5794 „���������¤������¤������������������¤��������������…
5795 63 48 47 40 39 16 15 0
5796 ACCESS SEGMENT BASE SEGMENT
5800 SYSTEM ADDRESS REGISTERS
5802 40-BIT EXPLICIT REGISTER
5803 ‚�����������������Ð����������ƒ
5804 GDTR € €GLOBAL DESCRIPTOR TABLE REGISTER
5805 Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘Â
5806 IDTR € €INTERRUPT DESCRIPTOR TABLE REGISTER
5807 „�����������������¤����������…
5813 VISIBLE 40-BIT HIDDEN
5814 SELECTOR DESCRIPTOR CACHE
5815 ‚����������Ð�����������������Ð����������ƒ
5816 LDTR€ � €LOCAL DESCRIPTOR TABLE REGISTER
5817 „����������¤�����������������¤����������…
5822 Figure 6-9. Descriptor Loading
5824 ’‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘“
5826 APPLICATION DESCRIPTOR
\a \a
5827 � VISIBLE CACHE � € SYSTEM €
5828 ’‘‘‘‘™‘‘‘‘‘“ ’‘‘‘‘™‘‘‘‘‘“ € MEMORY €
5829 � SEGMENT SEGMENT � € €
5830 REGISTER DESCRIPTOR € €
5831 � ‚����������ƒ ‚����������ƒ � € €
5832 € SELECTOR € € TYPE € € €
5833 � „�����Ð����… Ñ‘‘‘‘‘‘‘‘‘ � € €
5835 � � Ñ‘‘‘‘‘‘‘‘‘ � ¸ ¸
5837 � � „����������… � € €
5839 � � �TRANSPARENT� € €
5840 �DESCRIPTOR †���������������‡‘“
5841 � � �LOADING � € € �
5842 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Α‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
5843 � � � € € –‘DESCRIPTOR
5844 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ � TABLE
5845 � ”‘‘ ‘‘ ‘‘ ‘‘ ‘‘
\x10 \x1e INDEX � € € �
5846 ’ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘™ ‘‘ ‘‘ ‘‘
\x10†���������������‡‘•
5849 � €DESCRIPTOR€ � € €
5851 � „����������… �
\a \a
5852 ”‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘•
5855 6.6.2 System Address Registers
5857 The Global Descriptor Table Register (GDTR) is a dedicated 40-bit (5 byte)
5858 register used to record the base and size of a system's global descriptor
5859 table (GDT). Thus, two of these bytes define the size of the GDT, and three
5860 bytes define its base address.
5862 In figure 6-8, the contents of the GDTR are referred to as a "hidden
5863 descriptor." The term "descriptor" here emphasizes the analogy with the
5864 segment descriptors ordinarily found in descriptor tables. Just as these
5865 descriptors specify the base and size (limit) of ordinary segments, the
5866 GDTR register specifies these same parameters for that segment of memory
5867 serving as the system GDT. The limit prevents accesses to descriptors in the
5868 GDT from accessing beyond the end of the GDT and thus provides address space
5869 isolation at the system level as well as at the task level.
5871 The register contents are "hidden" only in the sense that they are not
5872 accessible by means of ordinary instructions. Instead, the dedicated
5873 protected instructions LGDT and SGDT are reserved for loading and storing,
5874 respectively, the contents of the GDTR at Protected Mode initialization
5875 (refer to section 10.2 for details). Subsequent alteration of the GDT base
5876 and size values is not recommended but is a system option at the most
5877 privileged level of software (see section 7.3 for a discussion of privilege
5880 The Local Descriptor Table Register (LDTR) is a dedicated 40-bit register
5881 that contains, at any given moment, the base and size of the local
5882 descriptor table (LDT) associated with the currently executing task. Unlike
5883 GDTR, the LDTR register contains both a "visible" and a "hidden" component.
5884 Only the visible component is accessible, while the hidden component remains
5885 truly inaccessible even to dedicated instructions.
5887 The visible component of the LDTR is a 16-bit "selector" field. The format
5888 of these 16 bits corresponds exactly to that of a segment selector in a
5889 virtual address pointer. Thus, it contains a 13-bit INDEX field, a 1-bit TI
5890 field, and a 2-bit RPL field. The TI "table indicator" bit must be zero,
5891 indicating a reference to the GDT (i.e., to global address space). The INDEX
5892 field consequently provides an index to a particular entry within the GDT.
5893 This entry, in turn, must be an LDT descriptor (or descriptor table
5894 descriptor), as defined in the previous section. In this way, the visible
5895 "selector" field of the LDTR, by selecting an LDT descriptor, uniquely
5896 designates a particular LDT in the system.
5898 The dedicated, protected instructions LLDT and SLDT are reserved for
5899 loading and storing, respectively, the visible selector component of the
5900 LDTR register (refer to section 10.2 for details). Whenever a new value is
5901 loaded into the visible "selector" portion of LDTR, an LDT descriptor will
5902 have been uniquely chosen (assuming, of course, that the "selector" value is
5903 valid). In this case, the 80286 automatically loads the hidden "descriptor"
5904 portion of LDTR with five bytes from the chosen LDT descriptor. Thus, size
5905 and base information about a particular LDT, as recorded in a
5906 memory-resident global descriptor table entry, is cached in the LDTR
5909 New values may be loaded into the visible portion of the LDTR (and, thus,
5910 into the hidden portion as well) in either of two ways. The LLDT
5911 instruction, during system initialization, is used explicitly to set an
5912 initial value for the LDTR register; in this way, a local address space is
5913 provided for the first task in a multitasking environment. After system
5914 startup, explicit changes are not required since operations that
5915 automatically invoke a task switch (described in section 8.4) appropriately
5918 At all times, the LDTR register thus records the physical base address (and
5919 size) of the current task's LDT; the descriptor table required for mapping
5920 the current local address space, therefore, is immediately accessible to the
5921 processor. Moreover, since GDTR always maintains the base address of the
5922 GDT, the table that maps the global address space is similarly accessible.
5923 The two system address registers, GDTR and LDTR, act as a special processor
5924 cache, maintaining current information about the two descriptor tables
5925 required, at any given time, for addressing the entire current virtual
5929 Chapter 7 Protection
5931 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
5935 In most microprocessor based products, the product's availability, quality,
5936 and reliability are determined by the software it contains. Software is
5937 often the key to a product's success. Protection is a tool used to shorten
5938 software development time, and improve software quality and reliability.
5940 Program testing is an important step in developing software. A system with
5941 protection will detect software errors more quickly and accurately than a
5942 system without protection. Eliminating errors via protection reduces the
5943 development time for a product.
5945 Testing software is difficult. Many errors occur only under complex
5946 circumstances which are difficult to anticipate. The result is that products
5947 are shipped with undetected errors. When such errors occur, products appear
5948 unreliable. The impact of a software error is multiplied if it introduces
5949 errors in other bug-free programs. Thus, the total system reliability
5950 reduces to that of the least reliable program running at any given time.
5952 Protection improves the reliability of an entire system by preventing
5953 software errors in one program from affecting other programs. Protection can
5954 keep the system running even when some user program attempts an invalid or
5955 prohibited operation.
5957 Hardware protection performs run-time checks in parallel with the execution
5958 of the program. But, hardware protection has traditionally resulted in a
5959 design that is more expensive and slower than a system without protection.
5960 However, the 80286 provides hardware-enforced protection without the
5961 performance or cost penalties normally associated with protection.
5963 The protected mode 80286 implements extensive protection by integrating
5964 these functions on-chip. The 80286 protection is more comprehensive and
5965 flexible than comparable solutions. It can locate and isolate a large number
5966 of program errors and prevent the propagation of such errors to other tasks
5967 or programs. The protection of the total system detects and isolates bugs
5968 both during development and installed usage. Chapter 9 discusses exceptions
5971 The remaining sections of this chapter explain the protection model
5972 implemented in the 80286.
5975 7.1.1 Types of Protection
5977 Protection in the 80286 has three basic aspects:
5979 1. Isolation of system software from user applications.
5980 2. Isolation of users from each other (Inter-task protection).
5981 3. Data-type checking.
5983 The 80286 provides a four-level, ringed-type, increasingly-privileged
5984 protection mechanism to isolate applications software from various layers of
5985 system software. This is a major improvement and extension over the simpler
5986 two-level user/supervisor mechanism found in many systems. Software modules
5987 in a supervisor level are protected from modules in the application level
5988 and from software in less privileged supervisor levels.
5990 Restricting the addressability of a software module enables an operating
5991 system to control system resources and priorities. This is especially
5992 important in an environment that supports multiple concurrent users.
5993 Multi-user, multi-tasking, and distributed processing systems require this
5994 complete control of system resources for efficient, reliable operation.
5996 The second aspect of protection is isolating users from each other. Without
5997 such isolation an error in one user program could affect the operation of
5998 another error-free user program. Such subtle interactions are difficult to
5999 diagnose and repair. The reliability of applications programs is greatly
6000 enhanced by such isolation of users.
6002 Within a system or application level program, the 80286 will ensure that
6003 all code and data segments are properly used (e.g., data cannot be executed,
6004 programs cannot be modified, and offset must be within defined limits,
6005 etc.). Such checks are performed on every memory access to provide full
6006 run-time error checking.
6009 7.1.2 Protection Implementation
6011 The protection hardware of the 80286 establishes constraints on memory and
6012 instruction usage. The number of possible interactions between instructions,
6013 memory, and I/O devices is practically unlimited. Out of this very large
6014 field the protection mechanism limits interactions to a controlled,
6015 understandable subset. Within this subset fall the list of "correct"
6016 operations. Any operation that does not fall into this subset is not allowed
6017 by the protection mechanism and is signalled as a protection violation.
6019 To understand protection on the 80286, you must begin with its basic parts:
6020 segments and tasks. 80286 segments are the smallest region of memory which
6021 have unique protection attributes. Modular programming automatically
6022 produces separate regions of memory (segments) whose contents are treated as
6023 a whole. Segments reflect the natural construction of a program, e.g., code
6024 for module A, data for module A, stack for the task, etc. All parts of the
6025 segment are treated in the same way by the 80286. Logically separate regions
6026 of memory should be in separate segments.
6028 The memory segmentation model (see figure 7-1) of the 80286 was designed to
6029 optimally execute code for software composed of independent modules. Modular
6030 programs are easier to construct and maintain. Compared to monolithic
6031 software systems, modular software systems have enhanced capabilities, and
6032 are typically easier to develop and test for proper operation.
6034 Each segment in the system is defined by a memory-resident descriptor. The
6035 protection hardware prevents accesses outside the data areas and attempts to
6036 modify instructions, etc., as defined by the descriptors. Segmentation on
6037 the 80286 allows protection hardware to be integrated into the CPU for full
6038 data access control without any performance impact.
6040 The segmented memory architecture of the 80286 provides unique capabilities
6041 for regulating the transfer of control between programs.
6043 Programs are given direct but controlled access to other procedures and
6044 modules. This capability is the heart of isolating application and system
6045 programs. Since this access is provided and controlled directly by the 80286
6046 hardware, there is no performance penalty. A system designer can take
6047 advantage of the 80286 access control to design high-performance modular
6048 systems with a high degree of confidence in the integrity of the system.
6050 Access control between programs and the operating system is implemented via
6051 address space separation and a privilege mechanism. The address space
6052 control separates applications programs from each other while the privilege
6053 mechanism isolates system software from applications software. The
6054 privilege mechanism grants different capabilities to programs to access
6055 code, data, and I/O resources based on the associated protection level.
6056 Trusted software that controls the whole system is typically placed at the
6057 most privileged level. Ordinary application software does not have to deal
6058 with these control mechanisms. They come into play only when there is a
6059 transfer of control between tasks, or if the Operating System routines have
6062 The protection features of multiple privilege levels extend to ensuring
6063 reliable I/O control. However, for a system designer to enable only one
6064 specific level to do I/O would excessively constrain subsequent extensions
6065 or application development. Instead, the 80286 permits each task to be
6066 assigned a separate minimum level where I/O is allowed. I/O privilege is
6067 discussed in section 10.3.
6069 An important distinction exists between tasks and programs. Programs (e.g.,
6070 instructions in code segments) are static and consist of a fixed set of code
6071 and data segments each with an associated privilege level. The privilege
6072 assigned to a program determines what the program may do when executed by a
6073 task. Privilege is assigned to a program when the system is built or when
6074 the program is loaded.
6076 Tasks are dynamic; they execute one or more programs. Task privilege
6077 changes with time according to the privilege level of the program being
6078 executed. Each task has a unique set of attributes that define it, e.g.,
6079 address space, register values, stack, data, etc. A task may execute a
6080 program if that program appears in the task's address space. The rules of
6081 protection control determine when a program may be executed by a task, and
6082 once executed, determine what the program may do.
6085 Figure 7-1. Addressing Segments of a Module within a Task
6094 ’‘‘‘‘‘‘‘‘‘‘‘“ ‚������ƒ
6095 � ‚�������ƒ � € CODE €
6096 � € CODE Ñš‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10Ñ‘‘‘‘‘ MODULE B
6097 � Ñ‘‘‘‘‘‘ � € DATA €
6098 � € DATA Ñš‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10„������…
6100 � € STACK Ñš‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“ ‚������ƒ
6101 � Ñ‘‘‘‘‘‘ � � € € TASK STACK
6102 � € EXTRA Ñš‘‘‘‘‘‘‘‘‘‘‘“ ”‘‘‘‘‘‘‘‘‘
\x10„������…
6104 � SEGMENT � � ‚������ƒ TASK
6105 � REGISTERS � � € € DATA
6106 ”‘‘‘‘‘‘‘‘‘‘‘• ”‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10„������… BLOCK 1
6115 7.2 Memory Management and Protection
6117 The protection hardware of the 80286 is related to the memory management
6118 hardware. Since protection attributes are assigned to segments, they are
6119 stored along with the memory management information in the segment
6120 descriptor. The protection information is specified when the segment is
6121 created. In addition to privilege levels, the descriptor defines the segment
6122 type (e.g., Code segment, Data segment, etc.). Descriptors may be created
6123 either by program development tools or by a loader in a dynamically loaded
6124 reprogrammable environment.
6126 The protection control information consists of a segment type, its
6127 privilege level, and size. These are fields in the access byte of the
6128 segment descriptor (see figure 7-2). This information is saved on-chip in
6129 the programmer invisible section of the segment register for fast access
6130 during execution. These entries are changed only when a segment register is
6131 loaded. The protection data is used at two times: upon loading a segment
6132 register and upon each reference to the selected segment.
6134 The hardware performs several checks while loading a segment register.
6135 These checks enforce the protection rules before any memory reference is
6136 generated. The hardware verifies that the selected segment is valid (is
6137 identified by a descriptor, is in memory, and is accessible from the
6138 privilege level in which the program is executing) and that the type is
6139 consistent with the target segment register. For example, you cannot load a
6140 read-only segment descriptor into SS because the stack must always be
6143 Each reference into the segment defined by a segment register is checked by
6144 the hardware to verify that it is within the defined limits of the segment
6145 and is of the proper type. For example, a code segment or read-only data
6146 segment cannot be written. All these checks are made before the memory cycle
6147 is started; any violation will prevent that cycle from starting and cause
6148 an exception to occur. Since the checks are performed concurrently with
6149 address formation, there is no performance penalty.
6151 By controlling the access rights and privilege attributes of segments, the
6152 system designer can assure a program will not change its code or overwrite
6153 data belonging to another task. Such assurances are vital to maintaining
6154 system integrity in the face of error-prone programs.
6157 Figure 7-2. Descriptor Cache Registers
6159 ’‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘“
6160 PROGRAM VISIBLE � PROGRAM INVISIBLE �
6163 SEGMENT SELECTORS RIGHTS SEGMENT BASE ADDRESS SEGMENT SIZE
6164 ‚�����������������ƒ � ‚������Ð����������������������Ð��������������ƒ �
6165 CSÑ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ Ñ‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6166 DSÑ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ � Ñ‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
6167 SSÑ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ Ñ‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6168 „�����������������… � „������¤����������������������¤��������������… �
6169 15 0 47 40 39 16 15 0
6171 SEGMENT REGISTERS SEGMENT DESCRIPTOR CACHE REGISTERS
6172 (loaded by program) � (loaded by CPU) �
6173 ”‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘•
6176 7.2.1 Separation of Address Spaces
6178 As described in Chapter 6, each task can address up to a gigabyte
6179 (2^(14) - 2 segments of up to 65,536 bytes each) of virtual memory defined
6180 by the task's LDT (Local Descriptor Table) and the system GDT. Up to
6181 one-half gigabyte (2^(13) segments of up to 65,536 bytes each) of the task's
6182 address space is defined by the LDT and represents the task's private
6183 address space. The remaining virtual address space is defined by the GDT and
6184 is common to all tasks in the system.
6186 Each descriptor table is itself a special kind of segment recognized by the
6187 80286 architecture. These tables are defined by descriptors in the GDT
6188 (Global Descriptor Table). The CPU has a set of base and limit registers
6189 that point to the GDT and the LDT of the currently running task. The local
6190 descriptor table register is loaded by a task switch operation.
6192 An active task can only load selectors that reference segments defined by
6193 descriptors in either the GDT or its private LDT. Since a task cannot
6194 reference descriptors in other LDTs, and no descriptors in its LDT refer to
6195 data or code belonging to other tasks, it cannot gain access to another
6196 tasks' private code and data (see figure 7-3).
6198 Since the GDT contains information that is accessible by all users (e.g.,
6199 library routines, common data, Operating System services, etc.), the 80286
6200 uses privilege levels and special descriptor types to control access (see
6201 section 7.2.2). Privilege levels protect more trusted data and code (in GDT
6202 and LDT) from less trusted access (WITHIN a task), while the private virtual
6203 address spaces defined by unique LDTs provide protection BETWEEN tasks (see
6207 Figure 7-3. 80286 Virtual Address Space
6209 ‚�������������������������������������ƒ
6210 ‚���������������������������������ƒ € ‚���������������������������������ƒ €
6211 € ‚������ƒ65535 € € € ‚������ƒ65535 € €
6212 € € SEG. €
\x18 € € € € SEG. €
\x18 € €
6213 € € €OFFSET€ € € € €OFFSET€ €
6214 € 8191‚�����ƒ ’‘
\x10„������…0
\x19 € € € 8191‚�����ƒ ’‘
\x10„������…0
\x19 € €
6215 €
\x18 € LDT Ñ‘‘•
\a € € €
\x18 € LDT Ñ‘‘•
\a € €
6216 €
\x19 € A Ñ‘‘“
\a € € €
\x19 € B Ñ‘‘“
\a € €
6217 € 0„�����… �
\a € € € 0„�����… �
\a € €
6218 € � ‚������ƒ65535 € € € � ‚������ƒ65535 € €
6219 € � € SEG. €
\x18 € € € � € SEG. €
\x18 € €
6220 € � € €OFFSET€ € € � € €OFFSET€ €
6221 € ”‘
\x10„������…0
\x19 € € € ”‘
\x10„������…0
\x19 € €
6222 „���������������������������������… € „���������������������������������… €
6223 TASK A PRIVATE ADDRESS SPACE € TASK B PRIVATE ADDRESS SPACE €
6225 ‚���������������������������������ƒ € ‚���������������������������������ƒ €
6226 € ‚������ƒ65535 € € € ‚������ƒ65535 € €
6227 € € SEG. €
\x18 € € € € SEG. €
\x18 € €
6228 € € €OFFSET€ € € € €OFFSET€ €
6229 € 8191‚�����ƒ ’‘
\x10„������…0
\x19 € € € 8191‚�����ƒ ’‘
\x10„������…0
\x19 € €
6230 €
\x18 € LDT Ñ‘‘•
\a € € €
\x18 € GDT Ñ‘‘•
\a € €
6231 €
\x19 € C Ñ‘‘“
\a € € €
\x19 € Ñ‘‘“
\a € €
6232 € 0„�����… �
\a € € € 0„�����… �
\a € €
6233 € � ‚������ƒ65535 € € € � ‚������ƒ65535 € €
6234 € � € SEG. €
\x18 € € € � € SEG. €
\x18 € €
6235 € � € €OFFSET€ € € � € €OFFSET€ €
6236 € ”‘
\x10„������…0
\x19 € € € ”‘
\x10„������…0
\x19 € €
6237 „���������������������������������… € „���������������������������������… €
6238 TASK C PRIVATE ADDRESS SPACE € SHARED ADDRESS SPACE €
6239 „�������������������������������������…
6240 TASK B ADDRESS SPACE
6242 Figure 7-4. Local and Global Descriptor Table Definitions
6246 ’‘˜‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
6247 � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
6248 CPU � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
6249 ‚���������������������ƒ � € ¨ € �
6250 € € � � € ¨ € –‘ GDT
6252 € ‚���������ƒ € � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
6253 € 23 €LDT LIMITÑ‘‘Α• Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
6254 € ‚���ð‘‘‘‘‘‘‘‘‘ € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
6255 GDTR € € GDT BASE Ñ‘‘Α‘‘‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
6256 € „�������������… € € €
6258 Ñ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ € €
6260 € 15 0 € ’‘˜‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
6261 € ‚����������ƒ € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
6262 € € LDT € € � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
6263 € € SELECTOR € € � € ¨ € �
6264 € „����������… € � � € ¨ € –‘ CURRENT LDT
6265 €’‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘“€ � € ¨ € �
6266 €� 15 0 �€ � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
6267 € ‚���������ƒ € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
6268 €� 23 €LDT LIMITÑ‘šÎ‘• � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
6269 € ‚���ð‘‘‘‘‘‘‘‘‘ € ’‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
6270 LDTR €� € LDT BASE Ñ‘šÃ‘‘• € €
6271 € „�������������… € € €
6272 €� PROGRAM INVISIBLE �€ € €
6273 €”‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘•€ € LDT{n} €
6274 „���������������������… Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6289 7.2.2 LDT and GDT Access Checks
6291 All descriptor tables have a limit used by the protection hardware to
6292 ensure address space separation of tasks. Each task's LDT can be a different
6293 size as defined by its descriptor in the GDT. The GDT may also contain less
6294 than 8191 descriptors as defined by the GDT limit value. The descriptor
6295 table limit identifies the last valid byte of the last descriptor in that
6296 table. Since each descriptor is eight bytes long, the limit value is
6297 N * 8 - 1 for N descriptors.
6299 Any attempt by a program to load a segment register, local descriptor table
6300 register (LDTR), or task register (TR) with a selector that refers to a
6301 descriptor outside the corresponding limit causes an exception with an error
6302 code identifying the invalid selector used (see figure 7-5).
6304 Not all descriptor entries in the GDT or LDT need contain a valid
6305 descriptor. There can be holes, or "empty" descriptors, in the LDT and GDT.
6306 "Empty" descriptors allow dynamic allocation and deletion of segments or
6307 other system objects without changing the size of the GDT or LDT. Any
6308 descriptor with an access byte equal to zero is considered empty. Any
6309 attempt to load a segment register with a selector that refers to an empty
6310 descriptor will cause an exception with an error code identifying the
6314 Figure 7-5. Error Code Format (on the stack)
6317 ‚���������������������������������������������������Ð���Ð���Ð���ƒ
6319 € INDEX � I � D � X €
6321 „���������������������������������������������������¤�Ð�¤�Ð�¤�Ð�…
6322 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � � �
6323 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � � �
6324 � ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � �
6325 � � ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• �
6327 ’‘‘‘‘‘‘‘“’‘‘‘‘‘‘‘‘‘“’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
6328 � Entry �� 1 means �� 1 means use �� 1 means that an event external to �
6329 � in �� use �� IDT and �� the program caused the exception �
6330 � IDT, �� LDT �� ignore �� (i.e., external interrupt, single �
6331 � GDT, �� 0 means �� bit 2. �� step, processor extension error) �
6332 � or �� use �� 0 means bit 2 �� 0 means that an exception occurred �
6333 � LDT �� GDT �� indicates �� while processing the instruction �
6334 � �� �� table usage �� at CS:IP saved on the stack. �
6335 ”‘‘‘‘‘‘‘•”‘‘‘‘‘‘‘‘‘•”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
6338 7.2.3 Type Validation
6340 After checking that a selector reference is within the bounds of a
6341 descriptor table and refers to a non-empty descriptor, the type of segment
6342 defined by the descriptor is checked against the destination register. Since
6343 each segment register has predefined functions, each must refer to certain
6344 types of segments (see section 7.4.1). An attempt to load a segment
6345 register in violation of the protection rules causes an exception.
6347 The "null" selector is a special type of segment selector. It has an index
6348 field of all zeros and a table indicator of 0. The null selector appears to
6349 refer to GDT descriptor entry #0 (see GDT in figure 7-3). This selector
6350 value may be used as a place holder in the DS or ES segment registers; it
6351 may be loaded into them without causing an exception. However, any attempt
6352 to use the null segment registers to reference memory will cause an
6353 exception and prevent any memory cycle from occurring.
6356 7.3 Privilege Levels and Protection
6358 As explained in section 6.2, each task has its own separate virtual address
6359 space defined by its LDT. All tasks share a common address space defined by
6360 the GDT. The system software then has direct access to task data and can
6361 treat all pointers in the same way.
6363 Protection is required to prevent programs from improperly using code or
6364 data that belongs to the operating system. The four privilege levels of the
6365 80286 provide the isolation needed between the various layers of the system.
6366 The 80286 privilege levels are numbered from 0 to 3, where 0 is the most
6367 trusted level, 3 the least.
6369 Privilege level is a protection attribute assigned to all segments. It
6370 determines which procedures can access the segment. Like access rights and
6371 limit checks, privilege checks are automatically performed by the hardware,
6372 and thus protect both data and code segments.
6374 Privilege on the 80286 is hierarchical. Operating system code and data
6375 segments placed at the most privileged level (0) cannot be accessed directly
6376 by programs at other privilege levels. Programs at privilege level 0 may
6377 access data at all other levels. Programs at privilege levels 1-3 may only
6378 access data at the same or less trusted (numerically greater) privilege
6379 levels. Figure 7-6 illustrates the privilege level protection of code or
6382 In figure 7-6, programs can access data at the same or outer level, but not
6383 at inner levels. Code and data segments placed at level 1 cannot be accessed
6384 by programs executing at levels 2 or 3. Programs at privilege level 0 can
6385 access data at level 1 in the course of providing service to that level.
6386 80286 provides mechanisms for inter-level transfer of control when needed
6389 The four privilege levels of the 80286 are an extension of the typical
6390 two-level user/supervisor privilege mechanism. Like user mode, application
6391 programs in the outer level are not permitted direct access to data
6392 belonging to more privileged system services (supervisor mode). The 80286
6393 adds two more privilege levels to provide protection for different layers of
6394 system software (system services, I/O drivers, etc.).
6397 Figure 7-6. Code and Data Segments Assigned to a Privilege Level
6400 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
6401 � ‚�����������������������������������������������ƒ �
6402 � € APPLICATIONS € �
6403 � € ‚�����������������������������������ƒ € �
6404 � € € CUSTOM EXTENSIONS € € �
6405 � € € ‚�����������������������ƒ € € �
6406 � € € € SYSTEM SERVICES € € € �
6407 � € € € ‚�����������ƒ € € € �
6408 � € € € € KERNAL € € € € �
6409 ã�Ñ‘‘‘‘Α‘‘‘‘Α‘‘‘‘Α‘‘‘‘˜‘‘‘‘‘Α‘‘‘‘Α‘‘‘‘Α‘‘‘‘Â�Á
6410 � € € € € �LEVEL€LEVEL€LEVEL€LEVEL€ �
6411 � € € € € � 0 € 1 € 2 € 3 € �
6412 � € € € „�����Ï�����… € € € �
6414 � € € „�����������Ï�����������… € € �
6416 � € „�����������������Ï�����������������… € �
6418 TASK B— „�����������������������¤�����������������������… –TASK A
6419 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
6422 7.3.1 Example of Using Four Privilege Levels
6424 Two extra privilege levels allow development of more reliable, and flexible
6425 system software. This is achieved by dividing the system into small,
6426 independent units. Figure 7-6 shows an example of the usage of different
6427 protection levels. Here, the most privileged level is called the kernel.
6428 This software would provide basic, application-independent, CPU-oriented
6429 services to all tasks. Such services include memory management, task
6430 isolation, multitasking, inter-task communication, and I/O resource
6431 control. Since the kernel is only concerned with simple functions and cannot
6432 be affected by software at other privilege levels, it can be kept small,
6433 safe, and understandable.
6435 Privilege level one is designated system services. This software provides
6436 high-level functions like file access scheduling, character I/O, data
6437 communcations, and resource allocation policy which are commonly expected in
6438 all systems. Such software remains isolated from applications programs and
6439 relies on the services of the kernel, yet cannot affect the integrity of
6442 Privilege level 2 is the custom operating system extensions level. It
6443 allows standard system software to be customized. Such customizing can be
6444 kept isolated from errors in applications programs, yet cannot affect the
6445 basic integrity of the system software. Examples of customized software are
6446 the data base manager, logical file access services, etc.
6448 This is just one example of protection mechanism usage. Levels 1 and 2 may
6449 be used in many different ways. The usage (or non-usage) is up to the system
6452 Programs at each privilege level are isolated from programs at outer
6453 layers, yet cannot affect programs in inner layers. Programs written for
6454 each privilege level can be smaller, easier to develop, and easier to
6455 maintain than a monolithic system where all system software can affect all
6456 other system software.
6459 7.3.2 Privilege Usage
6461 Privilege applies to tasks and three types of descriptors:
6463 1. Main memory segments
6465 2. Gates (control descriptors for state or task transitions, discussed
6466 in sections 7.5.1, 8.3, 8.4 and 9.2)
6468 3. Task state segments (discussed in Chapter 8).
6470 Task privilege is a dynamic value. It is derived from the code segment
6471 currently being executed. Task privilege can change only when a control
6472 transfers to a different code segment.
6474 Descriptor privilege, including code segment privilege, is assigned when
6475 the descriptor (and any associated segment) is created. The system designer
6476 assigns privilege directly when the system is constructed with the system
6477 builder (see the 80286 Builder User's Guide) or indirectly via a loader.
6479 Each task operates at only one privilege level at any given moment: namely
6480 that of the code segment being executed. (The conforming segments discussed
6481 in section 11.2 permit some flexibility in this regard.) However, as figure
6482 7-6 indicates, the task may contain segments at one, two, three, or four
6483 levels, all of which are to be used at appropriate times. The privilege
6484 level of the task, then, changes under the carefully enforced rules for
6485 transfer of control from one code segment to another.
6487 The descriptor privilege attribute is stored in the access byte of a
6488 descriptor and is called the Descriptor Privilege Level (DPL). Task
6489 privilege is called the Current Privilege Level (CPL). The least significant
6490 two bits of the CS register specify the CPL.
6492 A few general rules of privilege can be stated before the detailed
6493 discussions of later sections. Data access is restricted to those data
6494 segments whose privilege level is the same as or less privileged
6495 (numerically greater) than the current privilege level (CPL). Direct code
6496 access, e.g., via call or jump, is restricted to code segments of equal
6497 privilege. A gate (section 7.5.1) is required for access to code at more
6501 7.4 Segment Descriptor
6503 Although the format of access control information, discussed below, is
6504 similar for both data and code segment descriptors, the rules for accessing
6505 data segments differ from those for transferring control to code segments.
6506 Data segments are meant to be accessible from many privilege levels, e.g.,
6507 from other programs at the same level or from deep within the operating
6508 system. The main restriction is that they cannot be accessed by less
6511 Code segments, on the other hand, are meant to be executed at a single
6512 privilege level. Transfers of control that cross privilege boundaries are
6513 tightly restricted, requiring the use of gates. Control transfers within a
6514 privilege level can also use gates, but they are not required. Control
6515 transfers are discussed in section 7.5.
6517 Protection checks are automatically invoked at several points in selecting
6518 and using new segments. The process of addressing memory begins when the
6519 currently executing program attempts to load a selector into one of the
6520 segment registers. As discussed in Chapter 6, the selector has the form
6521 shown in figure 7-7.
6523 When a new selector is loaded into a segment register, the processor
6524 accesses the associated descriptor to perform the necessary loading and
6527 The protection mechanism verifies that the selector points to a valid
6528 descriptor type for the segment register (see section 7.4.1). After
6529 verifying the descriptor type, the CPU compares the privilege level of the
6530 task (CPL) to the privilege level in the descriptor (DPL) before loading
6531 the descriptor's information into the cache.
6533 The general format of the eight bits in the segment descriptor's access
6534 rights byte is shown in table 7-1.
6536 For example, the access rights byte for a data and code segment present in
6537 real memory but not yet accessed (at the same privilege level) is shown in
6540 Whenever a segment descriptor is loaded into a segment register, the
6541 accessed bit in the descriptor table is set to 1. This bit is useful for
6542 determining the usage profile of the segment.
6545 Table 7-1. Segment Access Rights Byte Format
6548 Bit Name Description
6550 7 Present 1 means Present and addressable in real memory;
6551 0 means not present. See section 11.3.
6553 6,5 DPL 2-bit Descriptor Privilege Level, 0 to 3.
6555 4 Segment 1 means Segment descriptor; 0 means control
6558 For Segment=1, the remaining bits have the following meanings:
6560 3 Executable 1 means code, 0 means data.
6562 2 C or ED If code, Conforming: 1 means yes, 0 no.
6563 If data, Expand Down: 1 yes, 0 no‘‘normal case.
6565 1 R or W If code, Readable: 1 means readable, 0 not.
6566 If data, Writable: 1 means writable, 0 not.
6568 0 Accessed 1 if segment descriptor has been Accessed, 0 if not.
6571 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
6573 When the Segment bit (bit 4) is 0, the descriptor is for a gate, a
6574 task state segment, or a Local Descriptor Table, and the meanings of bits
6575 0 through 3 change. Control transfers and descriptors are discussed in
6577 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
6579 Table 7-2. Allowed Segment Types in Segment Registers
6581 Allowed Segment Types
6582 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
6583 Segment Register Read Only Read-Write Execute Only Execute-Read
6584 Data Segment Data Segment Code Segment Code Segment
6590 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
6592 The Intel reserved bytes in the segment descriptor must be set to 0 for
6593 compatibility with the 80386.
6594 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
6596 Figure 7-7. Selector Fields
6599 ‚���������������������������������������������������Ð���Ð�������ƒ
6602 „���¤���¤���¤���¤���¤���¤���¤���¤���¤���¤���¤���¤���¤���¤���¤���…
6605 ‚������Ð����������������������Ð��������������������������������������������ƒ
6606 € BITS � NAME � FUNCTION €
6607 Ñ‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6608 € 1-0 � REQUESTED PRIVELEGE � INDICATES SELECTOR PRIVILEGE LEVEL DESIRED €
6610 Ñ‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6611 € 2 � TABLE INDICATOR (TI) � TI = 0 USE GLOBAL DESCRIPTOR TABLE (GDT) €
6612 € � � TI = 1 USE LOCAL DESCRIPTORTABLE (LDT) €
6613 Ñ‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6614 € 15-3 � INDEX � SELECT DESCRIPTOR ENTRY IN TABLE €
6615 „������¤����������������������¤��������������������������������������������…
6618 Figure 7-8. Access Byte Examples
6620 READABLE CODE SEGMENT WRITABLE CODE SEGMENT
6622 P DPL S E C R A P DPL S E ED W A
6623 ‚������������������������������ƒ ‚�������������������������������ƒ
6624 € 1 01 1 1 0 1 0 € € 1 01 1 0 0 1 0 €
6625 „������������������������������… „�������������������������������…
6631 Data may be accessed in data segments or readable code segments. When DS or
6632 ES is loaded with a new selector, e.g., by an LDS, LES, or MOV to ES, SS, or
6633 DS instruction, the bits in the access byte are checked to verify legitimate
6634 descriptor type and access (see table 7-2). If any test fails, an error
6635 code is pushed onto the stack identifying the selector involved (see figure
6636 7-5 for the error code format).
6638 A privilege check is made when the segment register is loaded. In general,
6639 a data segment's DPL must be numerically greater than or equal to the CPL.
6640 The DPL of a descriptor loaded into the SS must equal the CPL. Conforming
6641 code segments are an exception to privilege checking rules (see section
6644 Once the segment descriptor and selector are loaded, the offset of
6645 subsequent accesses within the segment are checked against the limit given
6646 in the segment descriptor. Violating the segment size limit causes a General
6647 Protection exception with an error code of 0.
6649 A normal data segment is addressed with offset values ranging from 0 to the
6650 size of the segment. When the ED bit of the access rights byte in the
6651 segment descriptor is 0, the allowed range of offsets is 0000H to the limit.
6652 If limit is 0FFFFH, the data segment contains 65,536 bytes.
6654 Since stacks normally occupy different offset ranges (lower limit to
6655 0FFFFH) than data segments, the limit field of a segment descriptor can be
6656 interpreted in two ways. The Expand Down (ED) bit in the access byte allows
6657 offsets for stack segments to be greater than the limit field. When ED is
6658 1, the allowed range of offsets within the segment is limit + 1 to 0FFFFH.
6659 To allow a full stack segment, set ED to 1 and the limit to 0FFFFH. The ED
6660 bit of a data segment descriptor does not have to be set for use in SS
6661 (i.e., it will not cause an exception). Section 7.5.1.4 discusses stack
6662 segment usage in greater detail. An expand down (ED=1) segment can also be
6663 loaded into ES or DS.
6665 Limit and access checks are performed before any memory reference is
6666 started. For stack push instructions (PUSH, PUSHA, ENTER, CALL, INT), a
6667 possible limit violation is identified before any internal registers are
6668 updated. Therefore, these instructions are fully restartable after a stack
6672 7.4.2 Code Segment Access
6674 Code segments are accessed via CS for execution. Segments that are
6675 execute-only can ONLY be executed; they cannot be accessed via DS or ES, nor
6676 read via CS with a CS override prefix. If a segment is executable (bit 3=1
6677 in the access byte), access via DS or ES is possible only if it is also
6678 readable. Thus, any code segment that also contains data must be readable.
6679 (Refer to Chapter 2 for a discussion of segment override prefixes.)
6681 An execute-only segment preserves the privacy of the code against any
6682 attempt to read it; such an attempt causes a general protection fault with
6683 an error code of 0. A code segment cannot be loaded into SS and is never
6684 writable. Any attempted write will cause a general protection fault with an
6687 The limit field of a code segment descriptor identifies the last byte in
6688 the segment. Any offset greater than the limit value will cause a general
6689 protection fault. The prefetcher of the 80286 can never cause a code segment
6690 limit violation with an error code of 0. The program must actually attempt
6691 to execute an instruction beyond the end of the code segment to cause an
6694 If a readable non-conforming code segment is to be loaded into DS or ES,
6695 the privilege level requirements are the same as those stated for data
6698 Code segments are subject to different privilege checks when executed. The
6699 normal privilege requirement for a jump or call to another code segment is
6700 that the current privilege level equal the descriptor privilege level of the
6701 new code segment. Jumps and calls within the current code segment
6702 automatically obey this rule.
6704 Return instructions may pass control to code segments at the same or less
6705 (numerically greater) privileged level. Code segments at more privileged
6706 levels may only be reached via a call through a call gate as described in
6709 An exception to this, previously stated, is the conforming code segment
6710 that allows the DPL of the requested code segment to be numerically less
6711 than (of greater privilege than) the CPL. Conforming code segments are
6712 discussed in section 11.2.
6715 7.4.3 Data Access Restriction by Privilege Level
6717 This section describes privilege verification when accessing either data
6718 segments (loading segment selectors into DS, ES, or SS) or readable code
6719 segments. Privilege verification when loading CS for transfer of control
6720 across privilege levels is described in the next section.
6722 Three basic kinds of privilege level indicators are used when determining
6723 accessibility to a segment for reading and writing. They are termed Current
6724 Privilege Level (CPL), Descriptor Privilege Level (DPL), and Requested
6725 Privilege Level (RPL). The CPL is simply the privilege level of the code
6726 segment that is executing (except if the current code segment is
6727 conforming). The CPL is stored as bits 0 and 1 of the CS and SS registers.
6728 Bits 0 and 1 of DS and ES are not related to CPL.
6730 DPL is the privilege level of the segment; it is stored in bits 5 and 6 of
6731 the access byte of a descriptor. For data access to data segments and
6732 non-conforming code segments, CPL must be numerically less than or equal to
6733 DPL (the task must be of equal or greater privilege) for access to be
6734 granted. Violation of this rule during segment load instruction causes a
6735 general protection exception with an error code identifying the selector.
6737 While the enforcement of DPL protection rules provides the mechanism for
6738 the isolation of code and data at different privilege levels, it is
6739 conceivable that an erroneous pointer passed onto a more trusted program
6740 might result in the illegal modification of data with a higher privilege
6741 level. This possibility is prevented by the enforcement of effective
6742 privilege level protection rules and correct usage of the RPL value.
6744 The RPL (requested privilege level) is used for pointer validation. It is
6745 the least significant two bits in the selector value loaded into any segment
6746 register. RPL is intended to indicate the privilege level of the originator
6747 of that selector. A selector may be passed down through several procedures
6748 at different levels. The RPL reflects the privilege level of the original
6749 supplier of the selector, not the privilege level of the intermediate
6750 supplier. The RPL must be numerically less than or equal to the DPL of the
6751 descriptor selected, thereby indicating greater or equal privilege of the
6752 supplier; otherwise, access is denied and a general protection violation
6755 Pointer validity testing is required in any system concerned with
6756 preventing program errors from destroying system integrity. The 80286
6757 provides hardware support for pointer validity testing. The RPL field
6758 indicates the privilege level of the originator of the pointer to the
6759 hardware. Access will be denied if the originator of the pointer did not
6760 have access to the selected segment even if the CPL is numerically less than
6761 or equal to the DPL. RPL can reduce the effective privilege of a task when
6762 using a particular selector. RPL never allows access to more privileged
6763 segments (CPL must always be numerically less than or equal to DPL).
6765 A fourth term is sometimes used: the Effective Privilege Level (EPL). It is
6766 defined as the numeric maximum of the CPL and the RPL‘‘meaning the one of
6767 lesser privilege. Access to a protected entity is granted only when the EPL
6768 is numerically less than or equal to the DPL of that entity. This is simply
6769 another way of saying that both CPL and RPL must be numerically less than
6770 or equal to DPL for access to be granted.
6773 7.4.4 Pointer Privilege Stamping via ARPL
6775 The ARPL instruction is provided in the 80286 to fill the RPL field of a
6776 selector with the minimum privilege (maximum numeric value) of the
6777 selector's current RPL and the caller's CPL (given in an
6778 instruction-specified register). A straight insertion of the caller's CPL
6779 would stamp the pointer with the privilege level of the caller, but not
6780 necessarily the ultimate originator of the selector (e.g., Level 3 supplies
6781 a selector to a level 2 routine that calls a level 0 routine with the same
6784 Figure 7-9 shows a program with an example of such a situation. The program
6785 at privilege level 3 calls a routine at level 2 via a gate. The routine at
6786 level 2 uses the ARPL instruction to assure that the selector's RPL is 3.
6787 When the level 2 routine calls a routine at level 0 and passes the
6788 selector, the ARPL instruction at level 0 leaves the RPL field unchanged.
6790 Stamping a pointer with the originator's privilege eliminates the complex
6791 and time-consuming software typically associated with pointer validation in
6792 less comprehensive architectures. The 80286 hardware performs the pointer
6793 test automatically while loading the selector.
6795 Privilege errors are trapped at the time the selector is loaded because
6796 pointers are commonly passed to other routines, and it may not be possible
6797 to identify a pointer's originator. To verify the access capabilities of a
6798 pointer, it should be tested when the pointer is first received from an
6799 untrusted source. The VERR (Verify Read), VERW (Verify Write), and LAR (Load
6800 Access Rights) instructions are provided for this purpose.
6802 Although pointer validation is fully supported in the 80286, its use is an
6803 option of the system designer. To accommodate systems that do not require
6804 it, RPL can be ignored by setting selector RPLs to zero (except stack
6805 segment selectors) and not adjusting them with the ARPL instruction.
6808 Figure 7-9. Pointer Privilege Stamping
6810 Level 3 PUSH SELECTOR ; RPL value doesn't matter at level 3
6815 MOV AX, [BP] + 4 ; GET CS of return address, RPL=3
6816 ARPL [BP] + 6, AX ; Put 3 in RPL field
6820 PUSH WORD PTR [BP] + 6 ; Pass selector
6825 Level 0 MOV AX, [BP] + 4 ; Get CS of return address, RPL=2
6826 ARPL [BP] + 6, AX ; Leaves RPL unchanged
6829 7.5 Control Transfers
6831 Three kinds of control transfers can occur within a task:
6833 1. Within a segment, causing no change of privilege level (a short jump,
6836 2. Between segments at the same privilege level (a long jump, call, or
6839 3. Between segments at different privilege levels (a long call, or
6840 return). (NOTE: A JUMP to a different privilege level is not allowed.)
6842 The first two types of control transfers need no special controls (with
6843 respect to privilege protection) beyond those discussed in section 7.4.
6845 Inter-level transfers require special consideration to maintain system
6846 integrity. The protection hardware must check that:
6848 Ž The task is currently allowed to access the destination address.
6849 Ž The correct entry address is used.
6851 To achieve control transfers, a special descriptor type called a gate is
6852 provided to mediate the change in privilege level. Control transfer
6853 instructions call the gate rather than transfer directly to a code segment.
6854 From the viewpoint of the program, a control transfer to a gate is the same
6855 as to another code segment.
6857 Gates allow programs to use other programs at more privileged levels in the
6858 same manner as a program at the same privilege level. Programmers need never
6859 distinguish between programs or subroutines that are more privileged than
6860 the current program and those that are not. The system designer may,
6861 however, elect to use gates only for control transfers that cross privilege
6867 A gate is a four-word control descriptor used to redirect a control
6868 transfer to a different code segment in the same or more privileged level or
6869 to a different task. There are four types of gates: call, trap, interrupt,
6870 and task gates. The access rights byte distinguishes a gate from a segment
6871 descriptor, and determines which type of gate is involved. Figure 7-10
6872 shows the format of a gate descriptor.
6874 A key feature of a gate is the re-direction it provides. All four gate
6875 types define a new address which transfers control when invoked. This
6876 destination address normally cannot be accessed by a program. Loading the
6877 selector to a call gate into SS, DS, or ES will cause a general protection
6878 fault with an error code identifying the invalid selector.
6880 Only the selector portion of an address is used to invoke a gate. The
6881 offset is ignored. All that a program need know about the desired function
6882 is the selector required to invoke the gate. The 80286 will automatically
6883 start the execution at the correct address stored within the gate.
6885 A further advantage of a gate is that it provides a fixed address for any
6886 program to invoke another program. The calling program's address remains
6887 unaltered even if the entry address of the destination program changes.
6888 Thus, gates provide a fixed set of entry points that allow a task to access
6889 Operating System functions such as simple subroutines, yet the task is
6890 prohibited from simply jumping into the middle of the Operating System.
6892 Call gates, as described in the next section, are used for control
6893 transfers within a task which must either be transparently redirected or
6894 which require an increase in privilege level. A call gate normally specifies
6895 a subroutine at a greater privilege level, and the called routine returns
6896 via a return instruction. Call gates also support delayed binding
6897 (resolution of target routine addresses at run-time rather than
6898 program-generation-time).
6900 Trap and interrupt gates handle interrupt operations that are to be
6901 serviced within the current task. Interrupt gates cause interrupts to be
6902 disabled; trap gates do not. Trap and interrupt gates both require a return
6903 via the interrupt return instruction.
6905 Task gates are used to control transfers between tasks and to make use of
6906 task state segments for task control and status information. Tasks are
6907 discussed in Chapter 8, interrupts in Chapter 9.
6909 In the 80286 protection model, each privilege level has its own stack.
6910 Therefore, a control transfer (call or return) that changes the privilege
6911 level causes a new stack to be invoked.
6914 Figure 7-10. Gate Descriptor Format
6917 ‚���������������������������������������������������������������ƒ
6919 Must be set to 0 for compatibility with the 80386 € +6
6920 Ñ‘‘˜‘‘‘‘‘‘‘˜‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6921 +5 € P � DPL � 0 � 0 1 0 1 � UNUSED € +4
6922 Ñ‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6923 +3 € TSS SELECTOR € +2
6924 Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6926 „���������������������������������������������������������������…
6929 Gate Descriptor Fields
6930 ‚���������������Ð����������Ð���������������������������������������������ƒ
6931 € Name � Value � Description €
6932 †���������������Ï����������Ï���������������������������������������������‡
6933 € � 4 � Call Gate. €
6934 € TYPE � 5 � Task Gate. €
6935 € � 6 � Interrupt Gate. €
6936 € � 7 � Trap Gate. €
6937 Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6938 € P � 0 � Descriptor Contents are not valid. €
6939 € � 1 � Descriptor Contents are valid. €
6940 Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6941 € DPL � 0-3 � Descriptor Privilege Level. €
6942 Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6943 € � 0-31 � Number of words to copy from caller's €
6944 € WORD COUNT � � stack to called procedure's stack. Only €
6945 € � � used with call gate. €
6946 Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6947 € � 16-bit � Selector to the target code segment (Call, €
6948 € DESTINATION � selector � Interrupt or Trap Gate). €
6949 € SELECTOR � � Selector to the target task state segment €
6950 € � � (Task Gate). €
6951 Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
6952 € DESTINATION � 16-bit � Entry point within the target code segment. €
6953 € OFFSET � offset � €
6954 „���������������¤����������¤���������������������������������������������…
6959 Call gate descriptors are used by call and jump instructions in the same
6960 manner as a code segment descriptor. The hardware automatically recognizes
6961 that the destination selector refers to a gate descriptor. Then, the
6962 operation of the instruction is expanded as determined by the contents of
6963 the call gate. A jump instruction can access a call gate only if the target
6964 code segment is at the same privilege level. A call instruction uses a call
6965 gate for the same or more privileged access.
6967 A call gate descriptor may reside in either the GDT or the LDT, but not in
6968 the IDT. Figure 7-10 gives the complete layout of a call gate descriptor.
6970 A call gate can be referred to by either the long JMP or CALL instructions.
6971 From the viewpoint of the program executing a JMP or CALL instruction, the
6972 fact that the destination was reached via a call gate and not directly from
6973 the destination address of the instruction is not apparent.
6975 The following is a description of the protection checks performed while
6976 transferring control (with the CALL instruction) through a call gate:
6978 Ž Verifying that access to the call gate is allowed. One of the
6979 protection features provided by call gates is the access checks made to
6980 determine if the call gate may be used (i.e., checking if the privilege
6981 level of the calling program is adequate).
6983 Ž Determining the destination address and whether a privilege transition
6984 is required. This feature makes privilege transitions transparent to
6987 Ž Performing the privilege transition, if required.
6989 Verifying access to a call gate is the same for any call gate and is
6990 independent of whether a JMP or CALL instruction was used. The rules of
6991 privilege used to determine whether a data segment may be accessed are
6992 employed to check if a call gate may be jumped-to or called. Thus,
6993 privileged subroutines can be hidden from untrusted programs by the absence
6996 When an inter-segment CALL or JMP instruction selects a call gate, the
6997 gate's privilege and presence will be checked. The gate's DPL (in the access
6998 byte) is checked against the EPL (MAX (task CPL, selector RPL)). If EPL >
6999 CPL, the program is less privileged than the gate and therefore it may not
7000 make a transition. In this case, a general protection fault occurs with an
7001 error code identifying the gate. Otherwise, the gate is accessible from the
7002 program executing the call, and the control transfer is allowed to continue.
7003 After the privilege checks, the descriptor presence is checked. If the
7004 present bit of the gate access rights byte is 0 (i.e., the target code
7005 segment is not present), not present fault occurs with an error code
7006 identifying the gate.
7008 The checks indicated in table 7-3 are applied to the contents of the call
7009 gate. Violating any of them causes the exception shown. The low order two
7010 bits of the error code are zero for these exceptions.
7013 Table 7-3. Call Gate Checks
7016 GP = General Protection, NP = Not-Present Exception Error Code
7017 Selector is not Null GP 0
7018 Selector is within Descriptor Table Limit GP Selector id
7019 Descriptor is a Code Segment GP Code Segment id
7020 Code Segment is Present NP Code Segment id
7021 Nonconforming Code Segment DPL > CPL GP Code Segment id
7023 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
7025 The offset portion of the JMP or CALL destination address which refers to
7026 a call gate is always ignored.
7027 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
7030 7.5.1.2 Intra-Level Transfers Via Call Gate
7032 The transfer is Intra-level if the destination code segment is at the same
7033 privilege level as CPL. Either the code segment is non-conforming with
7034 DPL = CPL, or it is conforming, with DPL ¾ CPL (see section 11.2 for this
7035 case). The 32-bit destination address in the gate is loaded into CS:IP.
7037 If the IP value is not within the limit of the code segment, a general
7038 protection fault occurs with an error code of 0. If a CALL instruction is
7039 used, the return address is saved in the normal manner. The only effect of
7040 the call gate is to place a different address into CS:IP than that
7041 specified in the destination address of the JMP or CALL instruction. This
7042 feature is useful for systems which require that a fixed address be provided
7043 to programs, even though the entry address for the routine may change due to
7044 different functions, software changes, or segment relocation.
7047 7.5.1.3 Inter-Level Control Transfer Via Call Gates
7049 If the destination code segment of the call gate is at a different
7050 privilege level than the CPL, an inter-level transfer is being requested.
7051 However, if the destination code segment DPL > CPL, then a general
7052 protection fault occurs with an error code identifying the destination code
7055 The gate guarantees that all transitions to a more privileged level will go
7056 to a valid entry point rather than possibly into the middle of a procedure
7057 (or worse, into the middle of an instruction). See figure 7-11.
7059 Calls to more privileged levels may be performed only through call gates. A
7060 JMP instruction can never cause a privilege change. Any attempt to use a
7061 call gate in this manner will cause a general protection fault with an error
7062 code identifying the gate. Returns to more privileged levels are also
7063 prohibited. Inter-level transitions due to interrupts use a different gate,
7064 as discussed in Chapter 9.
7066 The RPL field of the CS selector saved as part of the return address will
7067 always identify the caller's CPL. This information is necessary to correctly
7068 return to the caller's privilege level during the return instruction. Since
7069 the CALL instruction places the CS value on the more privileged stack, and
7070 JMP instructions cannot change privilege levels, it is not possible for a
7071 program to maliciously place an invalid return address on the caller's
7075 Figure 7-11. Call Gate
7077 ‚�������������Ð������������Ð��������������ƒ
7078 € CALL OPCODE � OFFSET � SELECTOR € INSTRUCTION
7079 „�������������¤������������¤������Ð�������…
7082 \a �ˆ��������������Ð��
\a \a���Ð��������������ˆ�
\a
7083 € CODE � � € DESCRIPTOR
7084 € SEG. � � CALL GATE € TABLES
7086 \a �‰����Ð���������¤��
\a \a���¤����Ð���Ð�����‰�
\a
7088 � ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘• � OFFSET
7090 \a �ˆ����������������������������������������ˆ�
\a
7094 \a �‰����������������������������������������‰�
\a
7097 7.5.1.4 Stack Changes Caused By Call Gates
7099 To maintain system integrity, each privilege level has a separate stack.
7100 Furthermore, each task normally uses separate stacks from other tasks for
7101 each privilege level. These stacks assure sufficient stack space to process
7102 calls from less privileged levels. Without them, trusted programs may not
7103 work correctly, especially if the calling program does not provide
7104 sufficient space on the caller's stack.
7106 When a call gate is used to change privilege levels, a new stack is
7107 selected as determined by the new CPL. The new stack pointer value is loaded
7108 from the Task State Segment (TSS). The privilege level of the new stack data
7109 segment must equal the new CPL; if it does not, a task stack fault occurs
7110 with the saved machine state pointing at the CALL instruction and the error
7111 code identifying the invalid stack selector.
7113 The new stack should contain enough space to hold the old SS:SP, the return
7114 address, and all parameters and local variables required to process the
7115 call. The initial stack pointers for privilege levels 0-2 in the TSS are
7116 strictly read only values. They are never changed during the course of
7119 The normal technique for passing parameters to a subroutine is to place
7120 them onto the stack. To make privilege transitions transparent to the called
7121 program, a call gate specifies that parameters are to be copied from the old
7122 stack to the new stack. The word count field in a call gate (see figure
7123 7-10) specifies how many words (up to 31) are to be copied from the
7124 caller's stack to the new stack. If the word count is zero, no parameters
7127 Before copying the parameters, the new stack is checked to assure that it
7128 is large enough to hold the parameters; if it is not, a stack fault occurs
7129 with an error code of 0. After the parameters are copied, the return link is
7130 on the new stack (i.e., a pointer to the old stack is placed in the new
7131 stack). In particular, the return address is pointed at by SS:SP. The call
7132 and return example of figure 7-12 illustrate the stack contents after a
7133 successful inter-level call.
7135 The stack pointer of the caller is saved above the caller's return address
7136 as the first two words pushed onto the new stack. The caller's stack can
7137 only be saved for calls to procedures at privilege levels 2, 1, and 0. Since
7138 level 3 cannot be called by any procedure at any other privilege level, the
7139 level 3 stack will never contain links to other stacks.
7141 Procedures requiring more than the 31 words for parameters that may be
7142 called from another privilege level must use the saved SS:SP link to access
7143 all parameters beyond the last word copied.
7145 The call gate does not check the values of the words copied onto the new
7146 stack. The called procedure should check each parameter for validity.
7147 Section 11.3 discusses how the ARPL, VERR, VERW, LSL, and LAR instructions
7148 can be used to check pointer values.
7151 Figure 7-12. Stack Contents after an Inter-Level Call
7153 \x1e ‚����������ƒ ‚����������ƒ
7155 � € € Ñ‘‘‘‘‘‘‘‘‘ � DIRECTION
7156 HIGHER € € € OLD SP € � OF STACK
7157 ADDRESSES € € Ñ‘‘‘‘‘‘‘‘‘ � GROWTH
7161 Ñ‘‘‘‘‘‘‘‘‘ Ñ‘‘‘‘‘‘‘‘‘ �
7162 € PARM 3 € € PARM 1 €
\x1f
7163 Ñ‘‘‘‘‘‘‘‘‘ Ñ‘‘‘‘‘‘‘‘‘Â
7164 € PARM 2 € € OLD CS €
7165 OLD Ñ‘‘‘‘‘‘‘‘‘ NEW Ñ‘‘‘‘‘‘‘‘‘Â
7166 SS:SP € PARM 1 € SS + SP € OLD IP €
7167 LOWER ”‘‘‘
\x10„����������… ”‘‘‘‘
\x10„����������…
7169 � OLD STACK NEW STACK
7170 � (AT "OUTER" (AT "INNER"
7171 \x1f PRIVILEGE PRIVILEGE
7175 7.5.2 Inter-Level Returns
7177 An inter-segment return instruction can also change levels, but only toward
7178 programs of equal or lesser privilege (when code segment DPL is numerically
7179 greater or equal than the CPL). The RPL of the selector popped off the stack
7180 by the return instruction identifies the privilege level to resume
7181 execution of the calling program.
7183 When the RET instruction encounters a saved CS value whose RPL > CPL, an
7184 inter-level return occurs. Checks shown in table 7-4 are made during such a
7187 The old SS:SP value is then adjusted by the number of bytes indicated in
7188 the RET instruction and loaded into SS:SP. The new SP value is not checked
7189 for validity. If SP is invalid it is not recognized until the first stack
7190 operation. The SS:SP value of the returning program is not saved. (Note:
7191 this value normally is the same as that saved in the TSS.)
7193 The last step in the return is checking the contents of the DS and ES
7194 descriptor register. If DS or ES refer to segments whose DPL is greater than
7195 the new CPL (excluding conforming code segments), the segment registers are
7196 loaded with the null selector. Any subsequent memory reference that
7197 attempts to use the segment register containing the null selector will cause
7198 a general protection fault. This prevents less privileged code from
7199 accessing more privileged data previously accessed by the more privileged
7203 Table 7-4. Inter-Level Return Checks
7205 Type of Check Exception
7206 SF = Stack Fault, GP = General Protection Exception, NP = Not-Present Error Code
7207 SP is not within Segment Limit SF 0
7208 SP + N + 7 is not in Segment Limit SF 0
7209 RPL of Return CS is Greater than CPL GP Return CS id
7210 Return CS Selector is not null GP Return CS id
7211 Return CS segment is within Descriptor GP Return CS id
7213 Return CS Descriptor is a Code Segment GP Return CS id
7214 Return CS Segment is Present NP Return CS id
7215 DPL of Return Non-Conforming Code GP Return CS id
7217 SS Selector at SP + N + 6 is not Null SF Return SS id
7218 SS Selector at SP + N + 6 is within SF Return SS id
7219 Descriptor Table Limit
7220 SS Descriptor is Writable Data Segment SF Return SS id
7221 SS Segment is Present SF Return SS id
7222 SS Segment DPL = RPL of CS SF Return SS id
7225 Chapter 8 Tasks and State Transitions
7227 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
7231 An 80286 task is a single, sequential thread of execution. Each task can be
7232 isolated from all other tasks. There may be many tasks associated with an
7233 80286 CPU, but only one task executes at any time. Switching the CPU from
7234 executing one task to executing another can occur as the result of either an
7235 interrupt or an inter-task CALL, JMP or IRET. A hardware-recognized data
7236 structure defines each task.
7238 The 80286 provides a high performance task switch operation with complete
7239 isolation between tasks. A full task-switch operation takes only 22
7240 microseconds at 8 MHz (18 microseconds at 10 MHz). High-performance,
7241 interrupt-driven, multi-application systems that need the benefits of
7242 protection are feasible with the 80286.
7244 A performance advantage and system design advantage arise from the 80286
7247 Ž Faster task switch: A task switch is a single instruction performed by
7248 microcode. Such a scheme is 2-3 times faster than an explicit task
7249 switch instruction. A fast task switch translates to a significant
7250 performance boost for heavily multi-tasked systems over conventional
7253 Ž More reliable, flexible systems: The isolation between tasks and the
7254 high speed task switch allows interrupts to be handled by separate
7255 tasks rather than within the currently interrupted task. This isolation
7256 of interrupt handling code from normal programs prevents undesirable
7257 interactions between them. The interrupt system can become more
7258 flexible since adding an interrupt handler is as safe and easy as
7261 Ž Every task is protected from all others via the separation of address
7262 spaces described in Chapter 7, including allocation of unique stacks
7263 to each active privilege level in each task (unless explicit sharing is
7264 planned in advance). If the address spaces of two tasks include no
7265 shared data, one task cannot affect the data of another task. Code
7266 sharing is always safe since code segments may never be written into.
7269 8.2 Task State Segments and Descriptors
7271 Tasks are defined by a special control segment called a Task State Segment
7272 (TSS). For each task, there must be an unique TSS. The definition of a task
7273 includes its address space and execution state. A task is invoked (made
7274 active) by inter-segment jump or call instructions whose destination
7275 address refers to a task state segment or a task gate.
7277 The Task State Segment (TSS) has a special descriptor. The Task Register
7278 within the CPU contains a selector to that descriptor. Each TSS selector
7279 value is unique, providing an unambiguous "identifier" for each task. Thus,
7280 an operating system can use the value of the TSS selector to uniquely
7283 A TSS contains 22 words that define the contents of all registers and
7284 flags, the initial stacks for privilege levels 0-2, the LDT selector, and a
7285 link to the TSS of the previously executing task. Figure 8-1 shows the
7286 layout of the TSS. The TSS can not be written into like an ordinary data
7289 Each TSS consists of two parts, a static portion and a dynamic portion. The
7290 static entries are never changed by the 80286, while the dynamic entries are
7291 changed by each task switch out of this task. The static portions of this
7292 segment are the task LDT selector and the initial SS:SP stack pointer
7293 addresses for levels 0-2.
7295 The modifiable or dynamic portion of the task state segment consists of all
7296 dynamically-variable and programmer-visible processor registers, including
7297 flags, segment registers, and the instruction pointer. It also includes the
7298 linkage word used to chain nested invocations of different tasks.
7300 The link word provides a history of which tasks invoked others. The link
7301 word is important for restarting an interrupted task when the interrupt has
7302 been serviced. Placing the back link in the TSS protects the identity of the
7303 interrupted task from changes by the interrupt task, since the TSS is not
7304 writable by the interrupt task. (In most systems only the operating system
7305 has sufficient privilege to create or use a writable data segment "alias"
7306 descriptor for the TSS.)
7308 The stack pointer entries in the TSS for privilege levels 0-2 are static
7309 (i.e., never written during a privilege or task switch). They define the
7310 stack to use upon entry to that privilege level. These stack entries are
7311 initialized by the operating system when the task is created. If a
7312 privilege level is never used, no stack need be allocated for it.
7314 When entering a more privileged level, the caller's stack pointer is saved
7315 on the stack of the new privilege level, not in the TSS. Leaving the
7316 privilege level requires popping the caller's return address and stack
7317 pointer off the current stack. The stack pointer at that time will be the
7318 same as the initial value loaded from the TSS upon entry to the privilege
7321 There is only one stack active at any time, the one defined by the SS and
7322 SP registers. The only other stacks that may be non-empty are those at outer
7323 (less privileged) levels that called the current level. Stacks for inner
7324 levels must be empty, since outward (to numerically larger privilege
7325 levels) calls from inner levels are not allowed.
7327 The location of the stack pointer for an outer privilege level will always
7328 be found at the start of the stack of the inner privilege level called by
7329 that level. That stack may be the initial stack for this privilege level or
7330 an outer level. Look at the start of the stack for this privilege level.
7331 The TSS contains the starting stack address for levels 0-2. If the RPL of
7332 the saved SS selector is the privilege level required, then the stack
7333 pointer has been found. Otherwise, go to the beginning of the stack defined
7334 by that value and look at the saved SS:SP value there.
7337 Figure 8-1. Task State Segment and TSS Registers
7340 ’‘Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
7341 � € INTEL RESERVED €
7342 � ј‘‘‘˜‘˜‘‘‘‘‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘€‘“
7344 ‚���Ð�����������������������������������ƒ
7346 †���Ï�����������������������������������‡
7347 € 1 � BASE AND LIMIT FIELDS ARE VALID €
7348 Ñ‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
7349 € 0 � SEGMENT IS NOT PRESENT IN MEMORY. €
7350 € � BASE AND LIMIT ARE NOT DEFINED €
7351 „���¤�����������������������������������…
7353 ‚����Ð����������������������������������������������ƒ
7355 †����Ï����������������������������������������������‡
7356 € 1 �AN AVAILABLE TASK STATE SEGMENT MAY BE USED €
7357 € �AS THE DESTINATION OF A TASK SWITCH OPERATION.€
7358 Ñ‘‘‘š‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
7359 € �A BUSY TASK STATE SEGMENT CANNOT BE USED AS €
7360 € �THE DESTINATION OF A TASK SWITCH. €
7361 „����¤����������������������������������������������…
7363 DESCRIPTOR ‘— Ñ™‘™‘™‘™‘™‘™‘™‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7364 \x1e � € BASE 15-0 € – “
7365 � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7366 � € LIMIT 15-0 € � �
7367 � ”‘Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
7368 CPU ’‘ ‘‘€‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘Î ‘‘•
7369 ‚��������������������Ï��ƒ ¸ ¸
7370 € TASK REGISTER € � €15 0€ BYTE
7371 € ‚�������ƒ � € ’‘Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ OFFSET
7372 € € Ñ‘ ‘• € � � € TASK LDT SELECTOR € 42
7373 Never altered (static) after initialization by O.S. The values as
7374 initialized for this task are always valid SS:SP values to use upon entry
7375 to that privilege level (0, 1, or 2) from a level of lesser privilege.
7376 € „�������… € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ ‘“
7377 € 15 0 € � � € DS SELECTOR € 40 �
7378 € ’‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘“ € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7379 € PROGRAM INVISIBLE € � � € SS SELECTOR € 38 �
7380 € � 15 0 � € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7381 € ‚�������ƒ “ € � � € CS SELECTOR € 36 �
7382 € � € LIMIT Ñ“ � � € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7383 € ‚���‰‘‘‘‘‘‘‘ � �
\x11‘ Α• � € ES SELECTOR € 34 �
7384 € � € BASE € � � � € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7385 € „Ð����������… � • € � € DI € 32 �
7386 € � � 0 � � € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7387 € ”‘‘�‘‘ ‘‘ ‘‘ ‘‘ š‘ ‘• € � € SI € 30 �
7388 „����Ï������������Ï�����… � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7389 � � � € BP € 28 �CURRENT
7390 � � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ –TASK
7391 � � � € SP € 26 �STATE
7392 Changed during task switch.
7393 � � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7395 � � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7396 � � TASK � € DX € 22 �
7397 � ”
\x10 STATE — Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7398 � SEGMENT � € CX € 20 �
7399 � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7401 � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7402 � � € FLAG WORD € 16 �
7403 � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7404 � � € IP (ENTRY POINT) € 14 �
7405 � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �Á
7406 � � € SS FOR CPL 2 € 12 �
7407 � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7408 � � € SP FOR CPL 2 € 10 �
7409 � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �INITIAL
7410 � � € SS FOR CPL 1 € 8 �STACKS
7411 � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ –FOR
7412 � � € SP FOR CPL 1 € 6 �CPL
7413 � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �0,1,2
7414 Never altered (static) after initialization by O.S. The values as
7415 initialized for this task are always valid SS:SP values to use upon entry
7416 to that privilege level (0, 1, or 2) from a level of lesser privilege.
7417 � � € SS FOR CPL 0 € 4 �
7418 � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
7419 � � € SP FOR CPL 0 € 2 �
7420 � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ ‘•
7421 � � € BACK LINK SELECTOR TO TSS € 0
\x11‘‘‘‘‘
7422 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
\x10”‘Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
7427 8.2.1 Task State Segment Descriptors
7429 A special descriptor is used for task state segments. This descriptor must
7430 be accessible at all times; therefore, it can appear only in the GDT. The
7431 access byte distinguishes TSS descriptors from data or code segment
7432 descriptors. When bits 0 through 4 of the access byte are 00001 or 00011,
7433 the descriptor is for a TSS.
7435 The complete layout of a task state segment descriptor is shown in figure
7438 Like a data segment, the descriptor contains a base address and limit
7439 field. The limit must be at least 002BH (43) to contain the minimum amount
7440 of information required for a TSS. An invalid task exception will occur if
7441 an attempt is made to switch to a task whose TSS descriptor limit is less
7442 than 43. The error code will identify the bad TSS.
7444 The P-bit (Present) flag indicates whether this descriptor contains
7445 currently valid information: 1 means yes, 0 no. A task switch that attempts
7446 to reference a not-present TSS causes a not-present exception code
7447 identifying the task state segment selector.
7449 The descriptor privilege level (DPL) controls use of the TSS by JMP or CALL
7450 instructions. By the same reasoning as that for call gates, DPL can prevent
7451 a program from calling the TSS and thereby cause a task switch. Section 8.3
7452 discusses privilege considerations during a task switch in greater detail.
7454 Bit 4 is always 0 since TSS is a control segment descriptor. Control
7455 segments cannot be accessed by SS, DS, or ES. Any attempt to load those
7456 segment registers with a selector that refers to a control segment causes
7457 general protection trap. This rule prevents the program from improperly
7458 changing the contents of a control segment.
7460 TSS descriptors can have two states: idle and busy. Bit 1 of the access
7461 byte distinguishes them. The distinction is necessary since tasks are not
7462 re-entrant; a busy TSS may not be invoked.
7465 Figure 8-2. TSS Descriptor
7468 ‚�������������������������������Ð�������������������������������ƒ
7470 Must be set to 0 for compatibility with 80836 €+6
7471 Ñ‘‘˜‘‘‘‘‘‘‘˜‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘˜‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
7472 +5€ P � DPL � 0 � 0 0 B � 1 � TSB BASE 23-16 €+4
7473 Ñ‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
7474 +3€ TSS BASE 15-0 €+2
7475 €‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘€
7477 „���������������������������������������������������������������…
7480 B=1 MEANS TASK IS BUSY AND NOT AVAILABLE
7485 A task switch may occur in one of four ways:
7487 1. The destination selector of a long JMP or CALL instruction refers to
7488 a TSS descriptor. The offset portion of the destination address is
7491 2. An IRET instruction is executed when the NT bit in the flag word = 1.
7492 The new task TSS selector is in the back link field of the current
7495 3. The destination selector of a long JMP or CALL instruction refers to
7496 a task gate. The offset portion of the destination address is ignored.
7497 The new task TSS selector is in the gate. (See section 8.5 for more
7498 information on task gates.)
7500 4. An interrupt occurs. This interrupt's vector refers to a task gate in
7501 the interrupt descriptor table. The new task TSS selector is in the
7502 gate. See section 9.4 for more information on interrupt tasks.
7504 No new instructions are required for a task switch operation. The standard
7505 8086 JMP, CALL, IRET, or interrupt operations perform this function. The
7506 distinction between the standard instruction and a task switch is made
7507 either by the type of descriptor referenced (for CALL, JMP, or INT) or by
7508 the NT bit (for IRET) in flag word.
7510 Using the CALL or INT instruction to switch tasks implies a return is
7511 expected from the called task. The JMP and IRET instructions imply no return
7512 is expected from the new task.
7514 When NT=1, the IRET instruction causes a return to the task that called the
7515 current one via CALL or INT instruction.
7517 Access to TSS and task gate descriptors is restricted by the rules of
7518 privilege level. The data access rules are used, thereby allowing task
7519 switches to be restricted to programs of sufficient privilege. Address space
7520 separation does not apply to TSS descriptors since they must be in the GDT.
7521 The access rules for interrupts are discussed in section 9.4.
7523 The task switch operation consists of the following eight steps:
7525 1. Validate the requested task switch. For a task switch requested via a
7526 JMP, CALL, or an INT instruction, check that the current task is
7527 allowed to switch to the requested task. The DPL of the gate or the
7528 TSS descriptor for the requested task must be greater than or equal
7529 to both the CPL and the RPL of the requesting task. If it is not, the
7530 General Protection fault (#13) will occur with an error code
7531 identifying the descriptor (i.e., the gate selector if the task
7532 switch is requested via a task gate, or the selector for the TSS if
7533 the task switch is requested via a TSS descriptor).
7535 These checks are not performed if a task switch occurs due to an IRET
7538 2. Check that the new TSS is present and that the new task is available
7539 (i.e. not Busy). A Not Present exception (#11) is signaled if the new
7540 TSS descriptor is marked 'Not Present' (P = 0). The General Protection
7541 exception (#13) is raised if the new TSS is marked 'Busy'.
7543 The task switch operation actually begins now and a detailed
7544 verification of the new TSS is carried out. Conditions which may
7545 disqualify the new TSS are listed in table 8-1 along with the
7546 exception raised and the error code pushed on the stack for each case.
7547 These tests are performed at different points during the course of the
7548 following remaining steps of the task switch operation.
7550 3. Mark the new task to be BUSY by setting the 'BUSY' bit in the new TSS
7553 4. Save the dynamic portion of the old TSS and load TR with the
7554 selector, base and limit for the new TSS. Set all CPU registers to
7555 corresponding values from the new TSS except DS, ES, CS, SS, and LDT.
7557 5. If nesting tasks, set the Nested Task (NT) flag in the new TSS to 1.
7558 Also set the Task Switched flag (TS) of the CPU flag register to 1.
7560 6. Validate the LDT selector and the LDT descriptor of the new TSS. Load
7561 the LDT cache (LDTR) with the LDT descriptor.
7563 7. Validate the SS, CS, DS, and ES fields of the new TSS and load these
7564 values in their respective caches (i.e., SS, CS, DS, and ES
7567 8. Validate the IP field of the new TSS and then start executing the new
7570 A more detailed explanation of steps 3-5 is given in Appendix B (80286
7571 Instruction Set) under a pseudo procedure 'SWITCH_TASKS'. Notice how the
7572 exceptions described in table 8-1 may actually occur during a task switch.
7573 Similarly the exceptions that may occur during steps 1-2, and step 8 are
7574 explained in greater detail in the pseudo code description of the 286
7575 instructions CALL, JMP, INT, and IRET in Appendix B. This information can
7576 be very helpful when debugging any protected mode code.
7578 Note that the state of the outgoing task is always saved. If execution of
7579 that task is resumed, it will start after the instruction that caused the
7580 task switch. The values of the registers will be the same as that when the
7581 task stopped running.
7583 Any task switch sets the Task Switched (TS) bit in the Machine Status Word
7584 (MSW). This flag is used when processor extensions such as the 80287 Numeric
7585 Processor Extension are present. The TS bit signals that the context of the
7586 processor extension may not belong to the current 80286 task. Chapter 11
7587 discusses the TS bit and processor extensions in more detail.
7589 Validity tests on a selector ensure that the selector is in the proper
7590 table (i.e., the LDT selector refers to GDT), lies within the bounds of the
7591 table, and refers to the proper type of descriptor (i.e., the LDT selector
7592 refers to the LDT descriptor).
7594 Note that between steps 3 and 4 in table 8-1, all the registers of the new
7595 task are loaded. Several protection rule violations may exist in the new
7596 segment register contents. If an exception occurs in the context of the new
7597 task due to checks performed on the newly loaded descriptors, the DS and ES
7598 segments may not be accessible even though the segment registers contain
7599 non-zero values. These selector values must be saved for later reuse. When
7600 the exception handler reloads these segment registers, another protection
7601 exception may occur unless the exception handler pre-examines them and
7602 fixes any potential problems.
7604 A task switch allows flexibility in the privilege level of the outgoing and
7605 incoming tasks. The privilege level at which execution resumes in the
7606 incoming task is not restricted by the privilege level of the outgoing task.
7607 This is reasonable, since both tasks are isolated from each other with
7608 separate address spaces and machine states. The privilege rules prevent
7609 improper access to a TSS. The only interaction between the tasks is to the
7610 extent that one started the other and the incoming task may restart the
7611 outgoing task by executing an IRET instruction.
7614 Table 8-1. Checks Made during a Task Switch
7618 NP = Not-Present Exception
7619 GP = General Protection Fault
7620 SF = Stack Fault Error Code
7621 1 Incoming TSS descriptor NP Incoming TSS selector
7623 2 Incoming TSS is idle G Incoming TSS selector
7624 3 Limit of incoming TSS Invalid TSS Incoming TSS selector
7626 4 LDT selector of incoming Invalid TSS LDT selector
7628 5 LDT of incoming TSS Invalid TSS LDT selector
7630 6 CS selector is valid Invalid TSS Code segment selector
7631 7 Code segment is present NP Code segment selector
7632 8 Code segment DPL matches Invalid TSS Code segment selector
7634 9 Stack segment is valid SF Stack segment selector
7635 10 Stack segment is writable GP Stack segment selector
7637 11 Stack segment is present SF Stack segment selector
7638 12 Stack segment DPL = CPL SF Stack segment selector
7639 13 DS/ES selectors are valid GP Segment selector
7640 14 DS/ES segments are readable GP Segment selector
7641 15 DS/ES segments are present NP Segment selector
7642 16 DS/ES segment DPL � CPL if GP Segment
7648 The TSS has a field called "back link" which contains the selector of the
7649 TSS of a task that should be restarted when the current task completes. The
7650 back link field of an interrupt-initiated task is automatically written with
7651 the TSS selector of the interrupted task.
7653 A task switch initiated by a CALL instruction also points the back link at
7654 the outgoing task's TSS. Such task nesting is indicated to programs via the
7655 Nested Task (NT) bit in the flag word of the incoming task.
7657 Task nesting is necessary for interrupt functions to be processed as
7658 separate tasks. The interrupt function is thereby isolated from all other
7659 tasks in the system. To restart the interrupted task, the interrupt handler
7660 executes an IRET instruction much in the same manner as an 8086 interrupt
7661 handler. The IRET instruction will then cause a task switch to the
7664 Completion of a task occurs when the IRET instruction is executed with the
7665 NT bit in the flag word set. The NT bit is automatically set/reset by task
7666 switch operations as appropriate. Executing an IRET instruction with NT
7667 cleared causes the normal 8086 interrupt return function to be performed,
7668 and no task switch occurs.
7670 Executing IRET with NT set causes a task switch to the task defined by the
7671 back link field of the current TSS. The selector value is fetched and
7672 verified as pointing to a valid, accessible TSS. The normal task switch
7673 operation described in section 8.3 then occurs. After the task switch is
7674 complete, the outgoing task is now idle and considered ready to process
7677 Table 8-2 shows how the busy bit, NT bit, and link word of the incoming and
7678 outgoing task are affected by task switch operations caused by JMP, CALL, or
7681 Violation of any of the busy bit requirements shown in table 8-2 causes a
7682 general protection fault with the saved machine state appearing as if the
7683 instruction had not executed. The error code identifies the selector of the
7684 TSS with the busy bit.
7686 A bus lock is applied during the testing and setting of the TSS descriptor
7687 busy bit to ensure that two processors do not invoke the same task at the
7688 same time. See also section 11.4 for other multi-processor considerations.
7690 The linking order of tasks may need to be changed to restart an interrupted
7691 task before the task that interrupted it completes. To remove a task from
7692 the list, trusted operating system software must change the backlink field
7693 in the TSS of the interrupting task first, then clear the busy bit in the
7694 TSS descriptor of the task removed from the list.
7696 When trusted software deletes the link from one task to another, it should
7697 place a value in the backlink field, which will pass control to that trusted
7698 software when the task attempts to resume execution of another task via
7702 Table 8-2. Effect of a Task Switch on BUSY and NT Bits and the Link Word
7706 Affected Field Instruction Instruction Instruction
7707 Effect Effect Effect
7709 Busy bit of incoming Set, must be Set, must be 0 Unchanged,
7710 task TSS descriptor 0 before before must be set
7712 Busy bit of outgoing Cleared Unchanged (will Cleared
7713 tasl TSS descriptor already be 1)
7715 NT bit in incoming task Cleared Set Unchanged
7718 NT bit in outgoing task Unchanged Unchanged Cleared
7721 Back link in incoming Unchanged Set to outgoing Unchanged
7722 task TSS task TSS selector
7724 Back link of outgoing Unchanged Unchanged Unchanged
7731 A task may be invoked by several different events. Task gates are provided
7732 to support this need. Task gates are used in the same way as call and
7733 interrupt gates. The ultimate effect of jumping to or calling a task gate is
7734 the same as jumping to or calling directly to the TSS in the task gate.
7736 Figure 8-3 depicts the layout of a task gate.
7738 A task gate is identified by the access byte field in bits 0 through 4
7739 being 00101. The gate provides an extra level of indirection between the
7740 destination address and the TSS selector value. The offset portion of the
7741 JMP or CALL destination address is ignored.
7743 Gate use provides flexibility in controlling access to tasks. Task gates
7744 can appear in the GDT, IDT, or LDT. The TSS descriptors for all tasks must
7745 be kept in the GDT. They are normally placed at level 0 to prevent any task
7746 from improperly invoking another task. Task gates placed in the LDT allow
7747 private access to selected tasks with full privilege control.
7749 The data segment access rules apply to accessing a task gate via JMP, CALL,
7750 or INT instructions. The effective privilege level (EPL) of the destination
7751 selector must be numerically less than or equal to the DPL of the task gate
7752 descriptor. Any violation of this requirement causes a general protection
7753 fault with an error code identifying the task gate involved.
7755 Once access to the task gate has been verified, the TSS selector from the
7756 gate is read. The RPL of the TSS selector is ignored. From this point, all
7757 the checks and actions performed for a JMP or CALL to a TSS after access has
7758 been verified are performed (see section 8.4). Figure 8-4 illustrates an
7759 example of a task switch through a task gate.
7762 Figure 8-3. Task Gate Descriptor
7765 ‚���������������������������������������������������������������ƒ
7767 Must be set to 0 for compatibility with 80386 €+6
7768 Ñ‘‘˜‘‘‘‘‘‘‘˜‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘˜‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
7769 +5€ P � DPL � O � O 1 O � 1 � UNUSED €+4
7770 Ñ‘‘™‘‘‘‘‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
7771 +3€ TSS SELECTOR €+2
7772 €‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘€
7774 „���������������������������������������������������������������…
7778 Figure 8-4. Task Switch Through a Task Gate
7781 ‚��������������ƒ ‚��������������ƒ ‚��������������ƒ
7784 € € Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘ € €
7785 € €TASK’€LDT DESCRIPTORÑ‘‘
\x10„��������������…
7786 € € B—Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘Â
\x11‘“ LDT
7787 ‚�������Ð��������ƒ Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘ ”€TSS DESCRIPTORÑ“�
7788 € �SELECTOR€
\x10€ TASK GATE €‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘ �� ‚��������������ƒ
7789 „�������¤��������… Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘ € € �”‘ LDT SELECTOR €
7790 ¸ ¸ € € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘Â
7792 „��������������…
\x11‘“ € € � € €
7794 ”‘‘Α‘‘‘‘‘‘‘‘‘‘‘‘‘ � € €
7795 ‚��������������ƒ‘‘‘‘
\x10€LDT DESCRIPTOR€“� € €
7796 € LDT SELECTOR € Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘Â�”‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘Â
7797 Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘ €TSS DESCRIPTOR€™“ € BACK LINK €
7798 € € ’‘‘Α‘‘‘‘‘‘‘‘‘‘‘‘‘Â
\x11‘‘‘„��������������…
7801 „��������������…
\x11‘• „��������������… A
7805 Chapter 9 Interrupts and Exceptions
7807 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
7809 Interrupts and exceptions are special cases of control transfer within a
7810 program. An interrupt occurs as a result of an event that is independent of
7811 the currently executing program, while exceptions are a direct result of the
7812 program currently being executed. Interrupts may be external or internal.
7813 External interrupts are generated by either the INTR or NMI input pins.
7814 Internal interrupts are caused by the INT instruction. Exceptions occur when
7815 an instruction cannot be completed normally. Although their causes differ,
7816 interrupts and exceptions use the same control transfer techniques and
7817 privilege rules; therefore, in the following discussions the term interrupt
7818 will also apply to exceptions.
7820 The program used to service an interrupt may execute in the context of the
7821 task that caused the interrupt (i.e., used the same TSS, LDT, stacks, etc.)
7822 or may be a separate task. The choice depends on the function to be
7823 performed and the level of isolation required.
7826 9.1 Interrupt Descriptor Table
7828 Many different events may cause an interrupt. To allow the reason for an
7829 interrupt to be easily identified, each interrupt source is given a number
7830 called the interrupt vector. Up to 256 different interrupt vectors (numbers)
7831 are possible. See figure 9-1.
7833 A table is used to define the handler for each interrupt vector. The
7834 Interrupt Descriptor Table (IDT) defines the interrupt handlers for up to
7835 256 different interrupts. The IDT is in physical memory, pointed to by the
7836 contents of the on-chip IDT register that contains a 24-bit base and a
7837 16-bit limit. The IDTR is normally loaded with the LIDT instruction by code
7838 that executes at privilege level 0 during system initialization. The IDT may
7839 be located anywhere in the physical address space of the 80286.
7841 Each IDT entry is a 4-word gate descriptor that contains a pointer to the
7842 handler. The three types of gates permitted in the IDT are interrupt gates,
7843 trap gates (discussed in section 9.3), and task gates (discussed in section
7844 9.5). Interrupt and task gates process interrupts in the same task, while
7845 task gates cause a task switch. Any other descriptor type in the IDT will
7846 cause an exception if it is referenced by an interrupt.
7848 The IDT need not contain all 256 entries. A 16-bit limit register allows
7849 less than the full number of entries. Unused entries may be signaled by
7850 placing a zero in the access rights byte. If an attempt is made to access an
7851 entry outside the table limit, or if the wrong descriptor type is found, a
7852 general protection fault occurs with an error code pushed on the stack
7853 identifying the invalid interrupt vector (see figure 9-2).
7855 Exception error codes that refer to an IDT entry can be identified by bit 1
7856 of the error code that will be set. Bit 0 of the error code is 1 if the
7857 interrupt was caused by an event external to the program (i.e., an external
7858 interrupt, a single step, a processor extension error, or a processor
7859 extension not present).
7861 Interrupts 0-31 are reserved for use by Intel. Some of the interrupts are
7862 used for instruction exceptions. The IDT limit must be at least 255
7863 (32 * 8 - 1) to accommodate the minimum number of interrupts. The remaining
7864 224 interrupts are available to the user.
7867 Figure 9-1. Interrupt Descriptor Table Definition
7872 ’‘†���������������‡‘“ CONTAIN
7873 � € GATE FOR € � INTERRUPT
7874 � € INTERRUPT #n € � GATES, TRAPS
7875 � †���������������‡ � OR TASK GATES
7876 � € GATE FOR € � ONLY.
7877 � €INTERRUPT #n-1 € �
7878 � †���������������‡ �
7880 ’‘
\x10‘— € ¨ € –‘ DESCRIPTOR
7881 � � € ¨ € � TABLE (IDT)
7882 CPU � � †���������������‡ �
7883 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“ � � € GATE FOR € �
7884 � 15 0 � � � € INTERRUPT #1 € �
7885 � ‚���������ƒ � � � †���������������‡ �
7886 � €IDT LIMITÑ‘š‘‘• � € GATE FOR € �
7887 IDTR � ‚���ð‘‘‘‘‘‘‘‘‘ � ”‘€ INTERRUPT #0 € �
7888 � € IDT BASE Ñ‘š‘‘‘‘‘‘‘
\x10†���������������‡‘•
7889 � „�������������… � € €
7891 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
7894 Figure 9-2. IDT Selector Error Code
7896 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
7897 ‚�������������������Ð�������������������������������Ð���Ð���Ð���ƒ
7899 € 0 0 0 0 0 � IDT VECTOR � 0 � 1 � X €
7901 „�������������������¤�������������������������������¤���¤���¤�Ð�…
7902 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
7904 1 An even external to the program
7905 caused the exception (i.e. external
7906 interrupt, single step, processor
7909 0 An exception occurred while
7910 processing an instruction at CS:IP
7914 9.2 Hardware Initiated Interrupts
7916 Hardware-initiated interrupts are caused by some external event that
7917 activates either the INTR or NMI input pins of the processor. Events that
7918 use the INTR input are classified as maskable interrupts. Events that use
7919 the NMI input are classified as non-maskable interrupts.
7921 All 224 user-defined interrupt sources share the INTR input, but each has
7922 the ability to use a separate interrupt handler. An 8-bit vector supplied by
7923 the interrupt controller identifies which interrupt is being signaled. To
7924 read the interrupt id, the processor performs the interrupt acknowledge bus
7927 Maskable interrupts (from the INTR input) can be inhibited by software by
7928 setting the interrupt flag bit (IF) to 0 in the flag word. The IF bit does
7929 not inhibit exceptions or interrupts caused by the INT instruction. The IF
7930 bit also does not inhibit processor extension interrupts.
7932 The type of gate placed into the IDT for the interrupt vector will control
7933 whether other maskable interrupts remain enabled or not during the servicing
7934 of that interrupt. The flag word that was saved on the stack reflects the
7935 maskable interrupt enable status of the processor prior to the interrupt.
7936 The procedure servicing a maskable interrupt can also prevent further
7937 maskable interrupts during its work by resetting the IF flag.
7939 Non-maskable interrupts are caused by the NMI input. They have a higher
7940 priority than the maskable interrupts (meaning that in case of simultaneous
7941 requests, the non-maskable interrupt will be serviced first). A non-maskable
7942 interrupt has a fixed vector (#2) and therefore does not require an
7943 interrupt acknowledge sequence on the bus. A typical use of an NMI is to
7944 invoke a procedure to handle a power failure or some other critical hardware
7947 A procedure servicing an NMI will not be further interrupted by other
7948 non-maskable interrupt requests until an IRET instruction is executed. A
7949 further NMI request is remembered by the hardware and will be serviced after
7950 the first IRET instruction. Only one NMI request can be remembered. To
7951 prevent a maskable interrupt from interrupting the NMI interrupt handler,
7952 the IF flag should be cleared either by using an interrupt gate in the IDT
7953 or by setting IF = 0 in the flag word of the task involved.
7956 9.3 Software Initiated Interrupts
7958 Software initiated interrupts occur explicitly as interrupt instructions or
7959 may arise as the result of an exceptional condition that prevents the
7960 continuation of program execution. Software interrupts are not maskable. Two
7961 interrupt instructions exist which explicitly cause an interrupt: INT n and
7962 INT 3. The first allows specification of any interrupt vector; the second
7963 implies interrupt vector 3 (Breakpoint).
7965 Other instructions like INTO, BOUND, DIV, and IDIV may cause an interrupt,
7966 depending on the overflow flag or values of the operands. These instructions
7967 have predefined vectors associated with them in the first 32 interrupts
7970 A whole class of interrupts called exceptions are intended to detect faults
7971 or programming errors (in the use of operands or privilege levels).
7972 Exceptions cannot be masked. They also have fixed vectors within the first
7973 32 interrupts. Many of these exceptions pass an error code on the stack,
7974 which is not the case with the other interrupt types discussed in section
7975 9.2. Section 9.5 discusses these error codes as well as the priority among
7976 interrupts that can occur simultaneously.
7979 9.4 Interrupt Gates and Trap Gates
7981 Interrupt gates and trap gates are special types of descriptors that may
7982 only appear in the interrupt descriptor table. The difference between a trap
7983 and an interrupt gate is whether the interrupt enable flag is to be cleared
7984 or not. An interrupt gate specifies a procedure that enters with interrupts
7985 disabled (i.e., with the interrupt enable flag cleared); entry via a trap
7986 gate leaves the interrupt enable status unchanged. The NT flag is always
7987 cleared (after the old NT state is saved on the stack) when an interrupt
7988 uses these gates. Interrupts that have either gate in the associated IDT
7989 entry will be processed in the current task.
7991 Interrupts and trap gates have the same structure as the call gates
7992 discussed in section 7.5.1. The selector and entry point for a code segment
7993 to handle the interrupt or exception is contained in the gate. See figure
7996 The access byte contains the Present bit, the descriptor privilege level,
7997 and the type identifier. Bits 0-4 of the access byte have a value of 00110
7998 for interrupt gates, 00111 for trap gates. Byte 5 of the descriptor is not
7999 used by either of these gates; it is used only by the call gate, which uses
8000 it as the parameter word-count.
8002 Trap and interrupt gates allow a privilege level transition to occur when
8003 passing control to a non-conforming code segment. Like a call gate, the DPL
8004 of the target code segment selected determines the new CPL. The DPL of the
8005 new non-conforming code segment must be numerically less than or equal to
8008 No privilege transition occurs if the new code segment is conforming. If
8009 the DPL of the conforming code segment is greater than the CPL, a general
8010 protection exception will occur.
8012 As with all descriptors, these gates in the IDT carry a privilege level.
8013 The DPL controls access to interrupts with the INT n and INT 3 instructions.
8014 For access, the CPL of the program must be less than or equal to the gate
8015 DPL. If the CPL is not, a general protection exception will result with an
8016 error code identifying the selected IDT gate. For exceptions and external
8017 interrupts, the CPL of the program is ignored while accessing the IDT.
8019 Interrupts using a trap or an interrupt gate are handled in the same manner
8020 as an 8086 interrupt. The flags and return address of the interrupted
8021 program are saved on the stack of the interrupt handler. To return to the
8022 interrupted program, the interrupt handler executes an IRET instruction.
8024 If an increase in privilege is required for handling the interrupt, a new
8025 stack will be loaded from the TSS. The stack pointer of the old privilege
8026 level will also be saved on the new stack in the same manner as a call gate.
8027 Figure 9-4 shows the stack contents after an exception with an error code
8028 (with and without a privilege level change).
8030 If an interrupt or trap gate is used to handle an exception that passes an
8031 error code, the error code will be pushed onto the new stack after the
8032 return address (as shown in figure 9-4). If a task gate is used, the error
8033 code is pushed onto the stack of the new task. The return address is saved
8036 If an interrupt gate is used to handle an interrupt, it is assumed that the
8037 selected code segment has sufficient privilege to re-enable interrupts. The
8038 IRET instruction will not re-enable interrupts if CPL is numerically greater
8041 Table 9-1 shows the checks performed during an interrupt operation that
8042 uses an interrupt or trap gate. EXT equals 1 when an event external to the
8043 program is involved; 0 otherwise. External events are maskable or
8044 non-maskable interrupts, single step interrupt, processor extension segment
8045 overrun interrupt, numeric processor not-present exception or numeric
8046 processor error. The EXT bit signals that the interrupt or exception is not
8047 related to the instruction at CS:IP. Each error code has bit 1 set to
8048 indicate an IDT entry is involved.
8050 When the interrupt has been serviced, the service routine returns control
8051 via an IRET instruction to the routine that was interrupted. If an error
8052 code was passed, the exception handler must remove the error code from the
8053 stack before executing IRET.
8055 The NT flag is cleared when an interrupt occurs which uses an interrupt or
8056 trap gate. Executing IRET with NT=0 causes the normal interrupt return
8057 function. Executing IRET with NT=1 causes a task switch (see section 8.4
8060 Like the RET instruction, IRET is restricted to return to a level of equal
8061 or lesser privilege unless a task switch occurs. The IRET instruction works
8062 like the inter-segment RET instruction except that the flag word is popped
8063 and no stack pointer update for parameters is performed since no parameters
8064 are on the stack. See section 7.5.2 for information on inter-level returns.
8066 To distinguish an inter-level IRET, the new CPL (which is the RPL of the
8067 return address CS selector) is compared with the current CPL. If they are
8068 the same, the IP and flags are popped and execution continues.
8070 An inter-level return via IRET has all the same checks as shown in table
8071 7-4. The only difference is the extra word on the stack for the old flag
8074 Interrupt gates are typically associated with high-priority hardware
8075 interrupts for automatically disabling interrupts upon their invocation.
8076 Trap gates are typically software-invoked since they do not disable the
8077 maskable hardware interrupts. However, low-priority interrupts (e.g., a
8078 timer) are often invoked via a trap gate to allow other devices of higher
8079 priority to interrupt the handler of that lower priority interrupt.
8081 Table 9-2 illustrates how the interrupt enable flag and interrupt type
8082 interact with the type of gate used.
8084 Table 9-1. Trap and Interrupt Gate Checks
8088 GP = General Protection Exception
8089 NP = Not Present Exception
8090 SF = Stack Fault Error Code
8092 Interrupt vector GP IDT entry * 8 + 2 + EXT
8095 Trap, Interrupt, or GP IDT entry * 8 + 2 + EXT
8096 Task Gate in IDT Entry
8098 If INT instruction, GP IDT entry * 8 + 2 + EXT
8101 P bit of gate is set NP IDT entry * 8 + 2 + EXT
8103 Code segment selector GP CS selector * 8 + EXT
8104 is in descriptor table limit
8106 CS selector refers GP CS selector * 8 + EXT
8109 If code segment is GP CS selector * 8 + EXT
8110 non-conforming, Code
8113 If code segment is TS SS selector * 8 + EXT
8120 If code segment is TS SS selector * 8 + EXT
8126 If code segment is TS Stack segment selector + EXT
8130 DPL = stack segment DPL
8132 If code segment is SF Stack segment selector + EXT
8137 If code segment is SF SS selector + EXT
8140 there is enough space
8141 for 5 words on the stack
8145 If code segment is GP Code segment selector + EXT
8146 conforming, then DPL ¾CPL
8148 If code segment NP Code segment selector + EXT
8151 If IP is not within GP 0 + EXT
8152 the limit of code segment
8155 Table 9-2. Interrupt and Gate Interactions
8157 Type of Type of Further Further Further Further software
8158 Interrupt Gate NMIs? INTRs? Exceptions? Interrupts?
8159 NMI Trap No Yes Yes Yes
8160 NMI Interrupt No No Yes Yes
8161 INTR Trap Yes Yes Yes Yes
8162 INTR Interrupt Yes No Yes Yes
8163 Software Trap Yes Yes Yes Yes
8164 Software Interrupt Yes No Yes Yes
8165 Exception Trap Yes Yes Yes Yes
8166 Exception Interrupt Yes No Yes Yes
8168 Figure 9-3. Trap/Interrupt Gate Descriptors
8170 ‚�������������������������������Ð�������������������������������ƒ
8172 Must be set to 0 for compatibility with IAPX 386 €+6
8173 Ñ‘‘˜‘‘‘‘‘‘‘˜‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘˜‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
8174 +5€ P � DP2 � 0 � 0 1 1 T � UNUSED €+4
8175 Ñ‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
8176 +3€ INTERRUPT CODE SEGMENT SELECTOR €+2
8177 €‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘€
8178 +1€ INTERRUPT CODE OFFSET € 0
8179 „���������������������������������������������������������������…
8183 T = 0 FOR INTERRUPT GATE
8186 Figure 9-4. Stack Layout after an Exception with an Error Code
8188 OLD SP‘‘‘‘‘
\x10‚����������������ƒ NO PRIVILEGE TRANSITION
8196 SP‘‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
8201 SS‘‘‘‘‘
\x10„����������������…
8203 SP FROM TSS‘ ‘ ‘
\x10‚����������������ƒ WITH PRIVILEGE TRANSITION
8215 SP‘‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
8220 SP FROM TSS‘‘‘‘‘
\x10„����������������…
8224 9.5 Task Gates and Interrupt Tasks
8226 The 80286 allows interrupts to directly cause a task switch. When an
8227 interrupt vector selects an entry in the IDT which is a task gate, a task
8228 switch occurs. The format of a task gate is described in section 8.5. If a
8229 task gate is used to handle an exception that passes an error code, the
8230 error code will be pushed onto the new task's stack.
8232 A task gate offers two advantages over interrupt gates:
8234 1. It automatically saves all of the processor registers as part of the
8235 task-switch operation, whereas an interrupt gate saves only the flag
8238 2. The new task is completely isolated from the task that was
8239 interrupted. Address spaces are isolated and the interrupt-handling
8240 task is unaffected by the privilege level of the interrupted task.
8242 An interrupt task switch works like any other task switch once the TSS
8243 selector is fetched from the task gate. Like a trap or an interrupt gate,
8244 privilege and presence rules are applied to accessing a task gate during an
8247 Interrupts that cause a task switch set the NT bit in the flags of the new
8248 task. The TSS selector of the interrupted task is saved in the back link
8249 field of the new TSS. The interrupting task executes IRET to perform a task
8250 switch to return to the interrupted task because NT was previously set. The
8251 interrupt task state is saved in its TSS before returning control to the
8252 task that was interrupted; NT is restored to its original value in the
8255 Since the interrupt handler state after executing IRET is saved, a re-entry
8256 of the interrupt service task will result in the execution of the
8257 instruction that follows IRET. Therefore, when the next interrupt occurs,
8258 the machine state will be the same as that when the IRET instruction was
8261 Note that an interrupt task resumes execution each time it is re-invoked,
8262 whereas an interrupt procedure starts executing at the beginning of the
8263 procedure each time. The interrupted task restarts execution at the point of
8264 interruption because interrupts occur before the execution of an
8267 When an interrupt task is used, the task must be concerned with avoiding
8268 further interrupts while it is operating. A general protection exception
8269 will occur if a task gate referring to a busy TSS is used while processing
8270 an interrupt. If subsequent interrupts can occur while the task is
8271 executing, the IF bit in the flag word (saved in the TSS) must be zero.
8274 9.5.1 Scheduling Considerations
8276 A software-scheduled operating system must be designed to handle the fact
8277 that interrupts can come along in the middle of scheduled tasks and cause a
8278 task switch to other tasks. The interrupt-scheduled tasks may call the
8279 operating system and eventually the scheduler, which needs to recognize
8280 that the task that just called it is not the one the operating system last
8283 If the Task Register (TR) does not contain the TSS selector of the last
8284 scheduled task, an interrupt initiated task switch has occurred. More than
8285 one task may have been interrupt-scheduled since the scheduler last ran. The
8286 scheduler must find via the backlink fields in each TSS all tasks that have
8287 been interrupted. The scheduler can clear those links and reset the busy bit
8288 in the TSS descriptors, putting them back in the scheduling queue for a new
8289 analysis of execution priorities. Unless the interrupted tasks are placed
8290 back in the scheduling queue, they would have to await a later restart via
8291 the task that interrupted them.
8293 To locate tasks that have been interrupt-scheduled, the scheduler looks
8294 into the current task's TSS backlink (word one of the TSS), which points at
8295 the interrupted task. If that task was not the last task scheduled, then
8296 it's backlink field in the TSS also points to an interrupted task.
8298 The backlink field of each interrupt-scheduled task should be set by the
8299 scheduler to point to a scheduling task that will reschedule the highest
8300 priority task when the interrupt-scheduled task executes IRET.
8303 9.5.2 Deciding Between Task, Trap, and Interrupt Gates
8305 Interrupts and exceptions can be handled with either a trap/interrupt gate
8306 or a task gate. The advantages of a task gate are all the registers are
8307 saved and a new set is loaded with full isolation between the interrupted
8308 task and the interrupt handler. The advantages of a trap/interrupt gate are
8309 faster response to an interrupt for simple operations and easy access to
8310 pointers in the context of the interrupted task. All interrupt handlers use
8311 IRET to resume the interrupted program.
8313 Trap/interrupt gates require that the interrupt handler be able to execute
8314 at the same or greater privilege level than the interrupted program. If any
8315 program executing at level 0 can be interrupted through a trap/task gate,
8316 the interrupt handler must also execute at level 0 to avoid general
8317 protection exception. All code, data, and stack segment descriptors must be
8318 in the GDT to allow access from any task. But, placing all system interrupt
8319 handlers at privilege level 0 may be in consistent with maintaining the
8320 integrity of level 0 programs.
8322 Some exceptions require the use of a task gate. The invalid task state
8323 segment exception (#10) can arise from errors in the original TSS as well as
8324 in the target TSS. Handling the exception within the same task could lead to
8325 recursive interrupts or other undesirable effects that are difficult to
8326 trace. The double fault exception (#8) should also use a task gate to
8327 prevent shutdown from another protection violation occurring during the
8328 servicing of the exception.
8331 9.6 Protection Exceptions and Reserved Vectors
8333 A protection violation will cause an exception, i.e., a non-maskable
8334 interrupt. Such a fault can be handled by the task that caused it if an
8335 interrupt or trap gate is used, or by a different task if a task gate is
8338 Protection exceptions can be classified into program errors or implicit
8339 requests for service. The latter include stack overflow and not-present
8340 faults. Examples of program errors include attempting to write into a
8341 read-only segment, or violating segment limits.
8343 Requests for service may use different interrupt vectors, but many diverse
8344 types of protection violation use the same general protection fault vector.
8345 Table 9-3 shows the reserved exceptions and interrupts. Interrupts 0-31 are
8348 When simultaneous external interrupt requests occur, they are processed in
8349 the fixed order shown in table 9-4. For each interrupt serviced, the
8350 machine state is saved. The new CS:IP is loaded from the gate or TSS. If
8351 other interrupts remain enabled, they are processed before the first
8352 instruction of the current interrupt handler, i.e., the last interrupt
8353 processed is serviced first.
8355 All but two exceptions are restartable after the exceptional condition is
8356 removed. The two non-restartable exceptions are the processor extension
8357 segment overrun and writing into read only segments with XCHG, ADC, SBB,
8358 RCL, and RCR instructions. The return address normally points to the failing
8359 instruction, including all leading prefixes.
8361 The instruction and data addresses for the processor extension segment
8362 overrun are contained in the processor extension status registers.
8364 Interrupt handlers for most exceptions receive an error code that
8365 identifies the selector involved, or a 0 in bits 15-3 of the error code
8366 field if there is no selector involved. The error code is pushed last,
8367 after the return address, on the stack that will be active when the trap
8368 handler begins execution. This ensures that the handler will not have to
8369 access another stack segment to find the error code.
8371 The following sections describe the exceptions in greater detail.
8374 Table 9-3. Reserved Exceptions and Interrupts
8376 Vector Description Restartable Code on
8378 0 Divide Error Exception Yes No
8379 1 Single Step Interrupt Yes No
8380 2 NMI Interrupt Yes No
8381 3 Breakpoint Interrupt Yes No
8382 4 INTO Detected Overflow Exception Yes No
8383 5 BOUND Range Exceeded Exception Yes No
8384 6 Invalid Opcode Exception Yes No
8385 7 Processor Extension Not Available
8387 8 Double Exception Detected No Yes (Always 0)
8388 9 Processor Extension Segment Overrun
8390 10 Invalid Task State Segment Yes Yes
8391 11 Segment Not Present Yes Yes
8392 12 Stack Segment Overrun or Not Present Yes Yes
8393 13 General Protection Yes
8394 Except for writes into read-only segments (see section 9.6) Yes
8397 Table 9-4. Interrupt Processing Order
8400 1 Instruction exception
8403 4 Processor extension segment overrun
8407 9.6.1 Invalid OP-Code (Interrupt 6)
8409 When an invalid opcode is detected by the execution unit, interrupt 6 is
8410 invoked. (It is not detected until an attempt is made to execute it, i.e.,
8411 prefetching an invalid opcode does not cause this exception.) The saved
8412 CS:IP will point to the invalid opcode or any leading prefixes; no error
8413 code is pushed on the stack. The exception can be handled within the same
8414 task, and is restartable.
8416 This exception will occur for all cases of an invalid operand. Examples
8417 include an inter-segment jump referencing a register operand, or an LES
8418 instruction with a register source operand.
8421 9.6.2 Double Fault (Interrupt 8)
8423 If two separate faults occur during a single instruction, end if the first
8424 fault is any of #0, #10, #11, #12, and #13, exception 8 (Double Fault)
8425 occurs (e.g., a general protection fault in level 3 is followed by a
8426 not-present fault due to a segment not-present). If another protection
8427 violation occurs during the processing of exception 8, the 80286 enters
8428 shutdown, during which time no further instructions or exceptions are
8431 Either NMI or RESET can force the CPU out of shutdown. An NMI input can
8432 bring the CPU out of shutdown if no errors occur while processing the NMI
8433 interrupt; otherwise, shutdown can only be exited via the RESET input. NMI
8434 causes the CPU to remain in protected mode, and RESET causes it to exit
8435 protected mode. Shutdown is signaled externally via a HALT bus operation
8438 A task gate must be used for the double fault handler to assure a proper
8439 task state to respond to the exception. The back link field in the current
8440 TSS will identify the TSS of the task causing the exception. The saved
8441 address will point at the instruction that was being executed (or was ready
8442 to execute) when the error was detected. The error code will be null.
8444 The "double fault" exception does not occur when detecting a new exception
8445 while trying to invoke handlers for the following exceptions: 1, 2, 3, 4, 5,
8449 9.6.3 Processor Extension Segment Overrun (Interrupt 9)
8451 Interrupt 9 signals that the processor extension (such as the 80287
8452 numerics processor) has overrun the limit of a segment while attempting to
8453 read/write the second or subsequent words of an operand. The interrupt is
8454 generated by the processor extension data channel within the 80286 during
8455 the limit test performed on each transfer of data between memory and the
8456 processor extension. This interrupt can be handled in the same task but is
8459 As with all external interrupts, Interrupt 9 is an asynchronous demand
8460 caused by the processor extension referencing something outside a segment
8461 boundary. Since Interrupt 9 can occur any time after the processor extension
8462 is started, the 80286 does not save any information that identifies what
8463 particular operation had been initiated in the processor extension. The
8464 processor extension maintains special registers that identify the last
8465 instruction it executed and the address of the desired operand.
8467 After this interrupt occurs, no WAIT or escape instruction, except FNINIT,
8468 can be executed until the interrupt condition is cleared or the processor
8469 extension is reset. The interrupt signals that the processor extension is
8470 requesting an invalid data transfer. The processor extension will always be
8471 busy when waiting on data. Deadlock results if the CPU executes an
8472 instruction that causes it to wait for the processor extension before
8473 resetting the processor extension. Deadlock means the CPU is waiting for the
8474 processor extension to become idle while the processor extension waits for
8475 the CPU to service its data request.
8477 The FNINIT instruction is guaranteed to reset the processor extension
8478 without causing deadlock. After the interrupt is cleared, this restriction
8479 is lifted. It is then possible to read the instruction and operand address
8480 via FSTENV or FSAVE, causing the segment overrun in the processor
8481 extension's special registers.
8483 The task interrupted by interrupt 9 is not necessarily the task that
8484 executed the ESC instruction that caused the interrupt. The operating system
8485 should keep track of which task last used the NPX (see section 11.4). If
8486 the interrupted task did not execute the ESC instruction, it can be
8487 restarted. The task that executed the ESC instruction cannot.
8490 9.6.4 Invalid Task State Segment (Interrupt 10)
8492 Interrupt 10 is invoked if during a task switch the new TSS pointed to by
8493 the task gate is invalid. The EXT bit indicates whether the exception was
8494 caused by an event outside the control of the program.
8496 A TSS is considered invalid in the cases shown in table 9-5.
8498 Once the existence of the new TSS is verified, the task switch is
8499 considered complete, with the backlink set to the old task if necessary. All
8500 errors are handled in the context of the new task.
8502 Exception 10 must be handled through a task gate to insure a proper TSS to
8503 process it. The handler must reset the busy bit in the new TSS.
8506 9.6.5 Not Present (Interrupt 11)
8508 Exception 11 occurs when an attempt is made to load a not-present segment
8509 or to use a control descriptor that is marked not-present. (If, however, the
8510 missing segment is an LDT that is needed in a task switch, exception 10
8511 occurs.) This exception is fully restartable.
8513 Any segment load instruction can cause this exception. Interrupt 11 is
8514 always processed in the context of the task in which it occurs.
8516 The error code has the form shown in Table 9-5. The EXT bit will be set if
8517 an event external to the program caused an interrupt that subsequently
8518 referenced a not-present segment. Bit 1 will be set if the error code refers
8519 to an IDT entry, e.g., an INT instruction referencing a not-present gate.
8520 The upper 14 bits are the upper 14 bits of the segment selector involved.
8522 During a task switch, when a not-present exception occurs, the ES and DS
8523 segment registers may not be usable for referencing memory (the selector
8524 values are loaded before the descriptors are checked). The not-present
8525 handler should not rely on being able to use the values found in ES, SS,
8526 and DS without causing another exception. This is because the task switch
8527 itself may have changed the values in the registers. The exception occurs in
8528 the new task and the return pointer points to the first instruction of the
8529 new task. Caution: the loading of the DS or ES descriptors may not have
8530 been completed. The exception II handler should ensure that the DS and ES
8531 descriptors have been properly loaded before the execution of the first
8532 instruction of the new task.
8535 Table 9-5. Conditions That Invalidate the TSS
8538 The limit in the TSS descriptor is less than 43 TSS id + EXT
8539 Invalid LDT selector or LDT not present LDT id + EXT
8540 Stack segment selector is null SS id + EXT
8541 Stack segment selector is outside table limit SS id + EXT
8542 Stack segment is not a writable segment SS id + EXT
8543 Stack segment DPL does not match new CPL SS id + EXT
8544 Stack segment selector RPL <> ECPL SS id + EXT
8545 Code segment selector is outside table limit CS id + EXT
8546 Code segment selector does not refer to code segment CS id + EXT
8547 Non-conforming code segment DPL <> ECPL CS id + EXT
8548 Conforming code segment DPL > CPL CS id + EXT
8549 DS or ES segment selector is outside table limits ES/DS id + EXT
8550 DS or ES are not readable segments ES/DS id + EXT
8553 9.6.6 Stack Fault (Interrupt 12)
8555 Stack underflow or overflow causes exception 12, as does a not-present
8556 stack segment referenced during an inter-task or inter-level transition.
8557 This exception is fully restartable. A limit violation of the current stack
8558 results in an error code of 0. The EXT bit of the error code tells whether
8559 an interrupt external to the program caused the exception.
8561 Any instruction that loads a selector to SS (e.g., POP SS, task switch) can
8562 cause this exception. This exception must use a task gate if there is a
8563 possibility that any level 0 stack may not be present.
8565 When a stack fault occurs, the ES and DS segment registers may not be
8566 usable for referencing memory. During a task switch, the selector values are
8567 loaded before the descriptors are checked. The stack fault handler should
8568 check the saved values of SS, CS, DS, and ES to be sure that they refer to
8569 present segments before restoring them.
8572 9.6.7 General Protection Fault (Interrupt 13)
8574 If a protection violation occurs which is not covered in the preceding
8575 paragraphs, it is classed as Interrupt 13, a general protection fault. The
8576 error code is zero for limit violations, write to read-only segment
8577 violations, and accesses relative to DS or ES when they are zero or refer
8578 to a segment at a greater privilege level than CPL. Other access violations
8579 (e.g., a wrong descriptor type) push a non-zero error code that identifies
8580 the selector used on the stack. Error codes with bit 0 cleared and bits
8581 15-2 non-zero indicate a restartable condition.
8583 Bit 1 of the error code identifies whether the selector is in the IDT or
8584 LDT/GDT. If bit 1 = 0 then bit 2 separates LDT from GDT. Bit 0 (EXT)
8585 indicates whether the exception was caused by the program or an event
8586 external to it (i.e., single stepping, an external interrupt, a processor
8587 extension not-present or a segment overrun). If bit 0 is set, the selector
8588 typically has nothing to do with the instruction that was interrupted. The
8589 selector refers instead to some step of servicing an interrupt that failed.
8591 When bit 0 of the error code is set, the interrupted program can be
8592 restarted, except for processor extension segment overrun exceptions (see
8593 section 9.6.3). The exception with the bit 0 of the errorcode = 1 indicates
8594 some interrupt has been lost due to a fault in the descriptor pointed to by
8597 A non-zero error code with bit 0 cleared may be an operand of the
8598 interrupted instruction, an operand from a gate referenced by the
8599 instruction, or a field from the invalid TSS.
8601 During a task switch, when a general protection exception occurs, the ES
8602 and DS segment registers may not be usable for referencing memory (the
8603 selector vaues are loaded before the descriptors are checked). The general
8604 protection handler should not rely on being able to use the values found in
8605 ES, SS, and DS without causing another exception. This is because the task
8606 switch itself may have changed the values in the registers. The exception
8607 occurs in the new task and the return pointer points to the first
8608 instruction of the new task. Caution: the loading of the DS or ES
8609 descriptors may not have been completed. The exception 13 handler should
8610 ensure that the DS and ES descriptors have been properly loaded before the
8611 execution of the first instruction of the new task.
8613 In Real Address Mode, Interrupt 13 will occur if software attempts to read
8614 or write a 16-bit word at segment offset 0FFFFH.
8617 9.7 Additional Exceptions and Interrupts
8619 Interrupts 0, 5, and 1 have not yet been discussed. Interrupt 0 is the
8620 divide-error exception, Interrupt 5 the bound-range exceeded exceptions, and
8621 Interrupt 1 the single step interrupt. The divide-error or bound-range
8622 exceptions make it appear as if that instruction had never executed: the
8623 registers are restored and the instruction can be restarted. The
8624 divide-error exception occurs during a DIV or an IDIV instruction when the
8625 quotient will be too large to be representable, or when the divisor is
8628 Interrupt 5 occurs when a value exceeds the limit set for it. A program can
8629 use the BOUND instruction to check a signed array index against signed
8630 limits defined in a two-word block of memory. The block can be located just
8631 before the array to simplify addressing. The block's first word specifies
8632 the array's lower limit, the second word specifies the array's upper limit,
8633 and a register specifies the array index to be tested.
8636 9.7.1 Single Step Interrupt (Interrupt 1)
8638 Interrupt 1 allows programs to execute one instruction at a time. This
8639 single-stepping is controlled by the TF bit in the flag word. Once this bit
8640 is set, an internal single step interrupt will occur after the next
8641 instruction has been executed. The interrupt saves the flags and return
8642 address on the stack, clears the TF bit, and uses an internally supplied
8643 vector of 1 to transfer control to the service routine via the IDT.
8645 The IRET instruction or a task switch must be used to set the TF bit and to
8646 transfer control to the next instruction to be single stepped. If TF=1 in a
8647 TSS and that task is invoked, it will execute the first instruction and then
8650 The single-step flag is normally not cleared by privilege changes inside a
8651 task. INT instructions, however, do clear TF. Therefore, software debuggers
8652 that single-step code must recognize and emulate INT n or INT 0 rather than
8653 executing them directly. System software should check the current execution
8654 privilege level after any single step interrupt to see whether single
8655 stepping should continue.
8657 The interrupt priorities in hardware guarantee that if an external
8658 interrupt occurs, single stepping stops. When both an external interrupt and
8659 a single step interrupt occur together, the single step interrupt is
8660 processed first. This clears the TF bit. After saving the return address or
8661 switching tasks, the external interrupt input is examined before the first
8662 instruction of the single step handler executes. If the external interrupt
8663 is still pending, it is then serviced. The external interrupt handler is
8664 not single-stepped. Therefore, to single step an interrupt handler, just
8665 single step an interrupt instruction that refers to the interrupt handler.
8668 Chapter 10 System Control and Initialization
8670 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
8672 Special flags, registers, and instructions provide contol of the critical
8673 processes and interaction in 80286 operations. The flag register includes 3
8674 bits that represent the current I/O privilege level (IOPL: 2 bits) and the
8675 nested task bit (NT). Four additional registers support the virtual
8676 addressing and memory protection features, one points to the current Task
8677 State Segment and the other three point to the memory-based descriptor
8678 tables: GDT, LDT, and IDT. These flags and registers are discussed in the
8679 next section. The machine status word, (which indicates processor
8680 configuration and status) and the instructions that load and store it are
8681 discussed in section 10.2.1.
8683 Similar instructions pertaining to the other registers are the subject of
8684 sections 10.2 and 10.3. A detailed description of initialization states
8685 and processes, which appears in section 10.4, is supplemented by the
8686 extensive example in Appendix A. Instructions that validate descriptors
8687 and pointers are covered in section 11.3.
8690 10.1 System Flags and Registers
8692 The IOPL flag (bits 12 and 13 of the flags word) controls access to I/O
8693 operations and interrupt control instructions. These two bits represent the
8694 maximum privilege level (highest numerical CPL) at which the task is
8695 permitted to perform I/O instructions. Alteration of the IOPL flags is
8696 restricted to programs at level 0 or to a task switch.
8698 IRET uses the NT flag to select the proper return: if NT=0, the normal
8699 return within a task is performed. As discussed in Chapter 8, the nested
8700 task flag (bit 14 of flags) is set when a task initiates a task switch via a
8701 CALL or INT instruction. The old and new task state segments are marked
8702 busy and the backlink field of the new TSS is set to the old TSS selector.
8703 An interrupt that does not cause a task switch will clear NT after the old
8704 NT state is saved. To prevent a program from causing an illegal task switch
8705 by setting NT and then executing IRET, a zero selector should be placed in
8706 the backlink field of the TSS. An illegal task switch using IRET will then
8707 cause exception 13. The instructions POPF and IRET can also set or clear NT
8708 when flags are restored from the stack. POPF and IRET can also change the
8709 interrupt enable flag. If CPL ¾ IOPL, then the Interrupt Flag (IF) can be
8710 changed by POPF and IRET. Otherwise, the state of the IF bit in the new
8711 flag word is ignored by these instructions. Note that the CLI and STI
8712 instructions are valid only when CPL ¾ IOPL; otherwise exception 13 occurs.
8715 10.1.1 Descriptor Table Registers
8717 The three descriptor tables used for all memory accesses are based at
8718 addresses supplied by (stored in) three registers: the global descriptor
8719 table register (GDTR), the interrupt descriptor table register (IDTR), and
8720 the local descriptor table register (LDTR). Each register contains a 24-bit
8721 base field and a 16-bit limit field. The base field gives the real memory
8722 address of the beginning of the table; the limit field tells the maximum
8723 offset permitted in accessing table entries. See figures 10-1, 10-2, and
8726 The LDTR also contains a selector field that identifies the descriptor for
8727 that table. LDT descriptors must reside in the GDT.
8729 The task register (TR) points to the task state segment for the currently
8730 active task. It is similar to a segment register, with selector, base, and
8731 limit fields, of which only the selector field is readable under normal
8732 circumstances. Each such selector serves as a unique identifier for its
8733 task. The uses of the TR are described in Chapter 8.
8735 The instructions controlling these special registers are described in the
8739 Figure 10-1. Local and Global Descriptor Table Definition
8743 ’‘˜‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
8744 � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
8745 CPU � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
8746 ‚���������������������ƒ � € ¨ € �
8747 € € � � € ¨ € –‘ GDT
8749 € ‚���������ƒ € � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
8750 € 23 €LDT LIMITÑ‘‘Α• Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
8751 € ‚���ð‘‘‘‘‘‘‘‘‘ € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
8752 GDTR € € GDT BASE Ñ‘‘Α‘‘‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
8753 € „�������������… € € €
8755 Ñ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ € €
8757 € 15 0 € ’‘˜‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“
8758 € ‚����������ƒ € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
8759 € € LDT € € � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
8760 € € SELECTOR € € � € ¨ € �
8761 € „����������… € � � € ¨ € –‘ CURRENT LDT
8762 €’‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘“€ � € ¨ € �
8763 €� 15 0 �€ � � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
8764 € ‚���������ƒ € � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
8765 €� 23 €LDT LIMITÑ‘šÎ‘• � Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘ �
8766 € ‚���ð‘‘‘‘‘‘‘‘‘ € ’‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
8767 LDTR €� € LDT BASE Ñ‘šÃ‘‘• € €
8768 € „�������������… € € €
8769 €� PROGRAM INVISIBLE �€ € €
8770 €”‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘•€ € LDT{n} €
8771 „���������������������… Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
8786 Figure 10-2. Interrupt Descriptor Table Definition
8791 ’‘‘‘˜‘
\x10†���������������‡‘“
8793 � � € INTERRUPT #n € �
8794 � †���������������‡ �
8796 � €INTERRUPT #n-1 € �
8797 � � †���������������‡ �
8799 � � € ¨ € –‘ DESCRIPTOR
8800 � € ¨ € � TABLE (IDT)
8801 CPU � � †���������������‡ �
8802 ’‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘“ � € GATE FOR € �
8803 � 15 0 � � � € INTERRUPT #1 € �
8804 � ‚���������ƒ � � †���������������‡ �
8805 � €IDT LIMITÑ‘š‘• � € GATE FOR € �
8806 � ‚���ð‘‘‘‘‘‘‘‘‘ � € INTERRUPT #0 € �
8807 IDTR � € IDT BASE Ñ‘š‘‘‘‘‘™‘
\x10†���������������‡‘•
8808 � „�������������… � € €
8810 ”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘•
8813 Figure 10-3. Data Type for Global Descriptor Table and
8814 Interrupt Descriptor Table
8817 ‚�������������������������������Ð�������������������������������ƒ
8819 Must be set to 0 for compatibility with the 80386 � BASE{23-16} €+4
8820 Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
8822 Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘™‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Â
8824 „�������������������������������¤�������������������������������…
8828 10.2 System Control Instructions
8830 The instructions that load the GDTR and IDTR from memory can only be
8831 executed in real address mode or at privilege level 0; otherwise exception
8832 13 occurs. The store instructions for GDTR and IDTR may be executed at any
8833 privilege level. The four instructions are LIDT, LGDT, SIDT, and SGDT. The
8834 instructions move 3 words between the indicated descriptor table register
8835 and the effective real memory address supplied (see figure 10-3). The
8836 format of the 3 words is: a 2-byte limit, a 3-byte real base address,
8837 followed by an unused byte. These instructions are normally used during
8838 system initialization.
8840 The LLDT instruction loads the LDT registers from a descriptor in the GDT.
8841 LLDT uses a selector operand to that descriptor rather than referencing the
8842 descriptor directly. LLDT is only executable at privilege level 0; otherwise
8843 exception 13 occurs. LLDT is normally required only during system
8844 initialization because the processor automatically exchanges the LDTR
8845 contents as part of the task-switch operation.
8847 Executing an LLDT instruction does not automatically update the TSS or the
8848 register caches. To properly change the LDT of the currently running task so
8849 that the change holds across task switches, you must perform, in order, the
8850 following three steps:
8852 1. Store the new LDT selector into the appropriate word of TSS.
8853 2. Load the new LDT selector into LDTR.
8854 3. Reload the DS and ES registers if they refer to LDT-based
8857 Note that the current code segment and stack segment descriptors should
8858 reside in the GDT or be copied to the same location in the new LDT.
8860 SLDT (store LDT) can be executed at any privilege level. SLDT stores the
8861 local descriptor table selector from the program visible portion of the LDTR
8864 Task Register loading or storing is again similar to that of the LDT. The
8865 LTR instruction, operating only at level 0, loads the LTR at initialization
8866 time with a selector for the initial TSS. LTR does NOT cause a task switch;
8867 it just changes the current TSS. Note that the busy bit of the old TSS
8868 descriptor is not changed while the busy bit of the new TSS selector must be
8869 zero and will be set by LTR. The LDT and any segment registers referring to
8870 the old LDT should be reloaded. STR, which permits the storing of TR
8871 contents into memory, can be executed at any privilege level. LTR is not
8872 usually needed after initialization because the TR is managed by the
8873 task-switch operation.
8876 10.2.1 Machine Status Word
8878 The Machine Status Word (MSW) indicates the 80286 configuration and status.
8879 It is not part of a task's state. The MSW word is loaded by the LMSW
8880 instruction executed in real address mode or at privilege level 0 only, or
8881 is stored by the SMSW instruction executing at any privilege level. MSW is a
8882 16-bit register, the lower four bits of which are used by the 80286. These
8883 bits have the meanings shown in table 10-1. Bits 15-4 of the MSW will be
8884 used by the 80386. 80286 software should not change these bits. If the bits
8885 are changed by the 286 software, compatibility with the 80386 will be
8888 The TS flag is set under hardware control and reset under software control.
8889 Once the TS flag is set, the next instruction using a processor extension
8890 causes a processor extension not-present exception (#7). This feature allows
8891 software to test whether the current processor extension state belongs to
8892 the current task as discussed in section 11.4. If the current processor
8893 extension state belongs to a different task, the software can save the state
8894 of any processor extension with the state of the task that uses it. Thus,
8895 the TS bit protects a task from processor extension errors that result from
8896 the actions of a previous task.
8898 The CLTS instruction is used to reset the TS flag after the exception
8899 handler has set up the proper processor extension state. The CLTS
8900 instruction can be executed at privilege level 0 only.
8902 The EM flag indicates a processor extension function is to be emulated by
8903 software. If EM=1 and MP=0, all ESCAPE instructions will be trapped via the
8904 processor extension not-present exception (#7).
8906 MP flag tells whether a processor extension is present. If MP=1 and TS=1,
8907 escape and wait instructions will cause exception 7.
8909 If ESC instructions are to be used, either the MP or the EM bit must be
8912 The PE flag indicates that the 80286 is in the protected virtual address
8913 mode. Once the PE flag is set, it can be cleared only by a reset, which then
8914 puts the system in real address mode emulating the 8086.
8916 Table 10-2 shows the recommended usage of the MSW. Other encodings of
8917 these bits are not recommended.
8919 Table 10-1. MSW Bit Functions
8922 Position Name Function
8923 0 PE Protected mode enable places the 80286 into protected
8924 mode and cannot be cleared except by RESET.
8926 1 MP Monitor processor extension allows WAIT instructions to
8927 cause a processor extension not-present exception
8928 (number 7) if TS is also set.
8930 2 EM Emulate processor extension causes a processor
8931 extension not-present exception (number 7) on
8932 ESC instructions to allow a processor extension to
8935 3 TS Task switched indicates the next instruction using a
8936 processor extension will cause exception 7, allowing
8937 software to test whether the current processor
8938 extension context belongs to the current task.
8941 Table 10-2. Recommended MSW Encodings for Processor Extension Control
8944 TS MP EM Recommended Use Instructions
8947 0 0 0 Initial encoding after RESET. 80286 operation
8948 is identical to 8086, 8088. Use this encoding
8949 only if no ESC instructions are to be executed. None
8951 0 0 1 No processor extension is available. Software
8952 will emulate its function. Wait instructions do
8953 not cause exception 7. ESC
8955 1 0 1 No processor extension is available. Software
8956 will emulate its function. The current processor
8957 extension context may belong to another task. ESC
8959 0 1 0 A processor extension exists. WAIT (if TS=1)
8961 1 1 0 A processor extension exists. The current
8962 processor extension context may belong to
8963 another task. The exception on WAIT allows
8964 software to test for an error pending from a
8965 previous processor extension operation. ESC or
8969 10.2.2 Other Instructions
8971 Instructions that verify or adjust access rights, segment limits, or
8972 privilege levels can be used to avoid exceptions or faults that are
8973 correctable. Section 10.3 describes such instructions.
8976 10.3 Privileged and Trusted Instructions
8978 Instructions that execute only at CPL=0 are called "privileged." An attempt
8979 to execute the privileged instructions at any other privilege level causes a
8980 general protection exception (#13) with an error code of zero. The
8981 privileged instructions manipulate descriptor tables or system registers.
8982 Incorrect use of these instructions can produce unrecoverable conditions.
8983 Some of these instructions (LGDT, LLDT, and LTR) are discussed in section
8986 Other privileged instructions are:
8988 Ž LIDT‘‘Load interrupt descriptor table register
8989 Ž LMSW‘‘Load machine status word
8990 Ž CLTS‘‘Clear task switch flag
8991 Ž HALT‘‘Halt processor execution
8992 Ž POPF (POP flags) or IRET can change the IF value only if the user is
8993 operating at a trusted privilege level. POPF does not change IOPL
8996 "Trusted" instructions are restricted to execution at a privilege level of
8997 CPL � IOPL. For each task, the operating system defines a privilege level
8998 below which these instructions cannot be used. Most of these instructions
8999 deal with input/output or interrupt management. The IOPL field in the flag
9000 word that holds the privilege level limit can be changed only when CPL=0.
9001 The trusted instructions are:
9003 Ž Input/Output‘‘Block I/O, Input, and Output: IN, INW, OUT, OUTW, INSB,
9006 Ž Interrupts‘‘Enable Interrupts, Disable Interrupts: STI, CLI
9008 Ž Other‘‘Lock Prefix
9013 Whenever the 80286 is initialized or reset, certain registers are set to
9014 predefined values. All additional desired initialization must be performed
9015 by user software. (See Appendix A for an example of a 286 initialization
9016 routine.) RESET forces the 80286 to terminate all execution and local bus
9017 activity; no instruction or bus action will occur as long as RESET is
9018 active. Execution in real address mode begins after RESET becomes inactive
9019 and an internal processing interval (3-4 clocks) occurs. The initial state
9025 CS Selector = F000H CS.base = FF0000H CS.limit = FFFFH
9026 CS Selector = 0000H CS.base = 000000H CS.limit = FFFFH
9027 ES Selector = 0000H ES.base = 000000H ES.limit = FFFFH
9028 IDT base = 000000H IDT.limit = 03FFH
9030 Two fixed areas of memory are reserved: the system initialization area and
9031 the interrupt table area. The system initialization area begins at FFFFF0H
9032 (through FFFFFFH) and the interrupt table area begins at 000000H (through
9033 0003FFH). The interrupt table area is not reserved.
9035 At this point, segment registers are valid and protection bits are set to
9036 0. The 80286 begins operation in real address mode, with PE=0. Maskable
9037 interrupts are disabled, and no processor extension is assumed or emulated
9040 DS, ES, and SS are initialized at reset to allow access to the first 64K of
9041 memory (exactly as in the 8086). The CS:IP combination specifies a starting
9042 address of FFFF0H. For real address mode, the four most significant bits are
9043 not used, providing the same FFF0H address as the 8086 reset location. Use
9044 of (or upgrade to) the protected mode can be supported by a bootstrap
9045 loader at the high end of the address space. As mentioned in Chapter 5,
9046 location FFF0H ordinarily contains a JMP instruction whose target is the
9047 actual beginning of a system initialization or restart program.
9049 After RESET, CS points to the top 64K bytes in the 16-Mbyte physical
9050 address space. Reloading CS register by a control transfer to a different
9051 code segment in real address mode will put zeros in the upper 4 bits. Since
9052 the initial IP is FFF0H, all of the upper 64K bytes of address space may be
9053 used for initialization.
9055 Sections 10.4.1 and 10.4.2 describe the steps needed to initialize the
9056 80286 in the real address mode and the protected mode, respectively.
9059 10.4.1 Real Address Mode
9061 1. Allocate a stack.
9063 2. Load programs and data into memory from secondary storage.
9065 3. Initialize external devices and the Interrupt Vector Table.
9067 4. Set registers and MSW bits to desired values.
9069 5. Set FLAG bits to desired values‘‘including the IF bit to enable
9070 interrupts‘‘after insuring that a valid interrupt handler exists for
9071 each possible interrupt.
9073 6. Execute (usually via an inter-segment JMP to the main system
9077 10.4.2 Protected Mode
9079 The full 80286 virtual address mode initialization procedure requires
9080 additional steps to operate correctly:
9082 1. Load programs and associated descriptor tables.
9084 2. Load valid GDT and IDT descriptor tables, setting the GDTR and IDTR to
9085 their correct value.
9087 3. Set the PE bit to enter protected mode.
9089 4. Execute an intra-segment JMP to clear the processor queues.
9091 5. Load or construct a valid task state segment for the initial task to
9092 be executed in protected mode.
9094 6. Load the LDTR selector from the task's GDT or 0000H (null) if an LDT
9097 7. Set the stack pointer (SS, SP) to a valid location in a valid stack
9100 8. Mark all items not in memory as not-present.
9102 9. Set FLAGS and MSW bits to correct values for the desired system
9105 10. Initialize external devices.
9107 11. Ensure that a valid interrupt handler exists for each possible
9110 12. Enable interrupts.
9114 The example in Appendix A shows the steps necessary to load all the
9115 required tables and registers that permit execution of the first task of a
9116 protected mode system. The program in Appendix A assumes that Intel
9117 development tools have been used to construct a prototype GDT, IDT, LDT,
9118 TSS, and all the data segments necessary to start up that first task.
9119 Typically, these items are stored on EPROM; on most systems it is necessary
9120 to copy them all into RAM to get going. Otherwise, the 80286 will attempt to
9121 write into the EPROM to set the accessed or busy bits.
9123 The example in Appendix A also illustrates the ability to allocate unused
9124 entries in descriptor tables to grow the tables dynamically during
9125 execution. Using suitable naming conventions, the builder can allocate alias
9126 data segments that are larger than the prototype EPROM version. The code in
9127 the example will zero out the extra entries to permit later dynamic usage.
9130 Chapter 11 Advanced Topics
9132 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
9134 This chapter describes some of the advanced topics as virtual memory
9135 management, restartable instructions, special segment attributes, and the
9136 validation of descriptors and pointers.
9139 11.1 Virtual Memory Management
9141 When access to a segment is requested and the access byte in its descriptor
9142 indicates the segment is not present in real memory, the not-present fault
9143 occurs (exception 11, or 12 for stacks). The handler for this fault can be
9144 set up to bring the absent segment into real memory (swapping or
9145 overwriting another segment if necessary), or to terminate execution of the
9146 requesting program if this is not possible.
9148 The accessed bit (bit 0) of the access byte is provided in both executable
9149 and data segment descriptors to support segment usage profiling. Whenever
9150 the descriptor is accessed by the 80286 hardware, the A-bit will be set in
9151 memory. This applies to selector test instructions (described below) as
9152 well as to the loading of a segment register. The reading of the access byte
9153 and the restoration of it with the A-bit set is an indivisible operation,
9154 i.e., it is performed as a read-modify-write with bus lock. If an operating
9155 system develops a profile of segment usage over time, it can recognize
9156 segments of low or zero access and choose among these candidates for
9159 When a not-present segment is brought into real memory, the task that
9160 requested access to it can continue its execution because all instructions
9161 that load a segment register are restartable.
9163 Not-present exceptions occur only on segment register load operations, gate
9164 accesses, and task switches. The saved instruction pointer refers to the
9165 first byte of the violating instruction. All other aspects of the saved
9166 machine state are exactly as they were before execution of the violating
9167 instruction began. After the fault handler clears up the fault condition and
9168 performs an IRET, the program continues to execute. The only external
9169 indication of a segment swap is the additional execution time.
9172 11.2 Special Segment Attributes
9175 11.2.1 Conforming Code Segments
9177 Code segments intended for use at potentially different privilege levels
9178 need an attribute that permits them to emulate the privilege level of the
9179 calling task. Such segments are termed "conforming" segments. Conforming
9180 segments are also useful for interrupt-driven error routines that need only
9181 be as privileged as the routine that caused the error.
9183 A conforming code segment has bit 2 of its access byte set to 1. This means
9184 it can be referenced by a CALL or JMP instruction in a task of equal or
9185 lesser privilege, i.e., CPL of the task is numerically greater than or equal
9186 to DPL of this segment. CPL does not change when executing the conforming
9187 code segment. A conforming segment continues to use the stack from the CPL.
9188 This is the only case in which the DPL of a code segment can be numerically
9189 less than the CPL. If bit 2 is a 0, the segment is not conforming and can be
9190 referenced only by a task of CPL = DPL.
9192 Inter-segment Returns that refer to conforming code segments use the RPL
9193 field of the code selector of the return address to determine the new CPL.
9194 The RPL becomes the new CPL if the conforming code segment DPL ¾ RPL.
9196 If a conforming segment is readable, it can be read from any privilege
9197 level without restriction. This is the only exception to the protection
9198 rules. This allows constants to be stored with conforming code. For example,
9199 a read-only look-up table can be embedded in a conforming code segment that
9200 can be used to convert system-wide logical ID's into character strings that
9201 represent those logical entities.
9204 11.2.2 Expand-Down Data Segments
9206 If bit 2 in the access byte of a data segment is 1, the segment is an
9207 expand-down segment. All the offsets that reference such a segment must be
9208 strictly greater than the segment limit, as opposed to normal data segments
9209 (bit 2 = 0) where all offsets must be less than or equal to the segment
9210 limit. Figure 11-1 shows an expand-down segment.
9212 The size of the expand down segment can be changed by changing either the
9213 base or the limit. An expand down segment with Limit = 0 will have a size of
9214 2^(16)-1 bytes. With a limit value of FFFFH, the expand down segment
9215 will have a size of 0 bytes. In an expand down segment, the base + offset
9216 value should always be greater than the base + limit value. Therefore, a
9217 full size segment (2^(16) bytes) can only be obtained by using an expand up
9220 The operating system should check the Expand-Down bit when a protection
9221 fault indicates that the limit of a data segment has been reached. If the
9222 Expand-Down bit is not set, the operating system should increase the segment
9223 limit; if it is set, the limit should be lowered. This supplies more room
9224 in either case (assuming the segment is not write-protected, i.e., that bit
9225 1 is not 0). In some cases, if the operating system can ascertain that there
9226 is not enough room to expand the data segment to meet the need that caused
9227 the fault, it can move the data segment to a region of memory where there
9228 is enough room. See figure 11-2.
9231 Figure 11-1. Expand-Down Segment
9236 BASE + FFFEH ‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘“
9241 BASE + OFFSET ‘‘‘‘
\x10€œœœœœœœœœœœœœ€ –‘ EXPAND DOWN
9242 >BASE + LIMIT €œœœœœœœœœœœœœ€ � SEGMENT
9246 BASE + LIMIT ‘‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘‘•
9251 ‘‘‘‘
\x10€‘‘ ‘‘ ‘‘ ‘‘ ‘€
9255 Figure 11-2. Dynamic Segment Relocation and Expansion of Segment Limit
9258 €œœœœœœœœœœœœœ€ €œœœœœœœœœœœœœ€
9259 €œœœœœœœœœœœœœ€ €œœœœœœœœœœœœœ€
9260 €œœœœœœœœœœœœœ€ BASE + 10000H‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘Â
9265 BASE + 10000H‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘ NEW BASE‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘Â
9266 € € + NEW LIMIT € SEG. B €
9268 € € NEW BASE‘‘‘
\x10€œœœœœœœœœœœœœ€
9270 OLD BASE‘‘‘
\x10Ñ‘‘‘‘‘‘‘‘‘‘‘‘ €œœœœœœœœœœœœœ€
9272 € SEG. A € € SEG. A €
9274 OLD BASE‘‘‘
\x10€œœœœœœœœœœœœœ€ €œœœœœœœœœœœœœ€
9275 €œœœœœœœœœœœœœ€ €œœœœœœœœœœœœœ€
9276 €œœœœœœœœœœœœœ€ €œœœœœœœœœœœœœ€
9277 €œœœœœœœœœœœœœ€ €œœœœœœœœœœœœœ€
9280 11.3 Pointer Validation
9282 Pointer validation is an important part of locating programming errors.
9283 Pointer validation is necessary for maintaining isolation between the
9284 privilege levels. Pointer validation consists of the following steps:
9286 1. Check if the supplier of the pointer is entitled to access the
9289 2. Check if the segment type is appropriate to its intended use.
9291 3. Check if the pointer violates the segment limit.
9293 The 80286 hardware automatically performs checks 2 and 3 during instruction
9294 execution, while software must assist in performing the first check. This
9295 point is discussed in section 11.3.2. Software can explicitly perform steps
9296 2 and 3 to check for potential violations (rather than causing an
9297 exception). The unprivileged instructions LSL, LAR, VERR, and VERW are
9298 provided for this purpose.
9300 The load access rights (LAR) instruction obtains the access rights byte of
9301 a descriptor pointed to by the selector used in the instruction. If that
9302 selector is visible at the CPL, the instruction loads the access byte into
9303 the specified destination register as the higher byte (the low byte is
9304 zero) and the zero flag is set. Once loaded, the access bits can be tested.
9305 System segments such as a task state segment or a descriptor table cannot be
9306 read or modified. This instruction is used to verify that a pointer refers
9307 to a segment of the proper privilege level and type. If the RPL or CPL is
9308 greater than DPL, or the selector is outside the table limit, no access
9309 value is returned and the zero flag is cleared. Conforming code segments may
9310 be accessed from any RPL or CPL.
9312 Additional parameter checking can be performed via the load segment limit
9313 (LSL) instruction. If the descriptor denoted by the given selector (in
9314 memory or a register) is visible at the CPL, LSL loads the specified
9315 register with a word that consists of the limit field of that descriptor.
9316 This can only be done for segments, task state segments, and local
9317 descriptor tables (i.e., words from control descriptors are inaccessible).
9318 Interpreting the limit is a function of the segment type. For example,
9319 downward expandable data segments treat the limit differently than code
9322 For both LAR and LSL, the zero flag (ZF) is set if the loading was
9323 performed; otherwise, the zero flag is cleared. Both instructions are
9324 undefined in real address mode, causing an invalid opcode exception
9328 11.3.1 Descriptor Validation
9330 The 80286 has two instructions, VERR and VERW, which determine whether a
9331 selector points to a segment that can be read or written at the current
9332 privilege level. Neither instruction causes a protection fault if the result
9335 VERR verifies a segment for reading and loads ZF with 1 if that segment is
9336 readable from the current privilege level. The validation process checks
9337 that: 1) the selector points to a descriptor within the bounds of the GDT or
9338 LDT, 2) it denotes a segment descriptor (as opposed to a control
9339 descriptor), and 3) the segment is readable and of appropriate privilege
9340 level. The privilege check for data segments and non-conforming code
9341 segments is that the DPL must be numerically greater than or equal to both
9342 the CPL and the selector's RPL. Conforming segments are not checked for
9345 VERW provides the same capability as VERR for verifying writability. Like
9346 the VERR instruction, VERW loads ZF if the result of the writability check
9347 is positive. The instruction checks that the descriptor is within bounds, is
9348 a segment descriptor, is writable, and that its DPL is numerically greater
9349 than or equal to both the CPL and the selector's RPL. Code segments are
9350 never writable, conforming or not.
9353 11.3.2 Pointer Integrity: RPL and the "Trojan Horse Problem"
9355 The Requested Privilege Level (RPL) feature can prevent inappropriate use
9356 of pointers that could corrupt the operation of more privileged code or data
9357 from a less privileged level.
9359 A common example is a file system procedure, FREAD (file_id, nybytes,
9360 buffer-ptr). This hypothetical procedure reads data from a file into a
9361 buffer, overwriting whatever is there. Normally, FREAD would be available at
9362 the user level, supplying only pointers to the file system procedures and
9363 data located and operating at a privileged level. Normally, such a procedure
9364 prevents user-level procedures from directly changing the file tables.
9365 However, in the absence of a standard protocol for checking pointer
9366 validity, a user-level procedure could supply a pointer into the file
9367 tables in place of its buffer pointer, causing the FREAD procedure to
9368 corrupt them unwittingly.
9370 By using the RPL, you can avoid such problems. The RPL field allows a
9371 privilege attribute to be assigned to a selector. This privilege attribute
9372 would normally indicate the privilege level of the code which generated the
9373 selector. The 80286 hardware will automatically check the RPL of any
9374 selector loaded into a segment register or a control register to see if the
9377 To guard against invalid pointers, the called procedure need only ensure
9378 that all selectors passed to it have an RPL at least as high (numerically)
9379 as the original caller's CPL. This indicates that the selectors were not
9380 more trusted than their supplier. If one of the selectors is used to access
9381 a segment that the caller would not be able to access directly, i.e., the
9382 RPL is numerically greater than the DPL, then a protection fault will result
9383 when loaded into a segment or control register.
9385 The caller's CPL is available in the CS selector that was pushed on the
9386 stack as the return address. A special instruction, ARPL, can be used to
9387 appropriately adjust the RPL field of the pointer. ARPL (Adjust RPL field of
9388 selector instruction) adjusts the RPL field of a selector to become the
9389 larger of its original value and the value of the RPL field in a specified
9390 register. The latter is normally loaded from the caller's CS register which
9391 can be found on the stack. If the adjustment changes the selector's RPL, ZF
9392 is set; otherwise, the zero flag is cleared.
9395 11.4 NPX Context Switching
9397 The context of a processor extension (such as the 80287 numerics processor)
9398 is not changed by the task switch operation. A processor extension context
9399 need only be changed when a different task attempts to use the processor
9400 extension (which still contains the context of a previous task). The 80286
9401 detects the first use of a processor extension after a task switch by
9402 causing the processor extension not-present exception (#7) if the TS bit is
9403 set. The interrupt handler may then decide whether a context change is
9406 The 286 services numeric errors only when it executes wait or escape
9407 instructions because the processor extension is running independently.
9408 Therefore, the numerics error from one task may not be recorded until the
9409 286 is running a different task. If the 286 task has changed, it makes
9410 sense to defer handling that error until the original task is restored. For
9411 example, interrupt handlers that use the NPX should not have their timing
9412 upset by a numeric error interrupt that pertains to some earlier process.
9413 It is of little value to service someone else's error.
9415 If the task switch bit is set (bit 3 of MSW) when the CPU begins to execute
9416 a wait or escape instruction, the processor-extension not-present exception
9417 results (#7). The handler for this interrupt must know who currently "owns"
9418 the NPX, i.e., the handler must know the last task to issue a command to the
9419 NPX. If the owner is the same as the current task, then it was merely
9420 interrupted and the interrupt handler has since returned; the handler for
9421 interrupt 7 simply clears the TS bit, restores the working registers, and
9422 returns (restoring interrupts if enabled).
9424 If the recorded owner is different from the current task, the handler must
9425 first save the existing NPX context in the save area of the old task. It can
9426 then re-establish the correct NPX context from the current task's save area.
9428 The code example in figure 11-3 relies on the convention that each TSS
9429 entry in the GDT is followed by an alias entry for a data segment that
9430 points to the same physical region of memory that contains the TSS. The
9431 alias segment also contains an area for saving the NPX context, the kernel
9432 stack, and certain kernel data. That is, the first 44 bytes in that segment
9433 are the 286 context, followed by 94 bytes for the processor extension
9434 context, followed in some cases by the kernel stack and kernel private data
9437 The implied convention is that the stack segment selector points to this
9438 data segment alias so that whenever there is an interrupt at level zero and
9439 SS is automatically loaded, all of the above information is immediately
9442 It is assumed that the program example knows about only one data segment
9443 that points to a global data area in which it can find the one word NPX
9444 owner to begin the processing described. The specific operations needed, and
9445 shown in the figure, are listed in table 11-1.
9448 Table 11-1. NPX Context Switching
9450 Step Operation Lines
9453 1. Save the working registers 28, 29
9454 2. Set up address for kernel work area 30, 31
9455 3. Get current task ID from Task Register 32
9456 4. Clear Task Switch flag to allow NPX work 34
9457 5. Inhibit interrupts 35
9458 6. Compare owner with current task ID 37
9461 7a. Restore working registers 48, 49
9464 If owner is not current task:
9465 8a. Use owner ID to save old context
9466 in its TSS 42, 43, 44
9467 8b. Restore context of current task; 45
9468 restore working registers; 46
9471 Figure 11-3. Example of NPX Context Switching
9473 ASSEMBLER INVOKED BY: ASM286,86 :FS:SWNPX.A86
9476 1 + 1 $title('Switch the NPX Context on First Use After a Task Switch')
9478 3 name switch_npx_context
9480 5 public switch_NPX_context
9481 6 extrn last_npx_task:word
9483 8 ; This interrupt handler will switch the NPX context if a new task
9484 9 ; is attempting to use the NPX context of another task after a task
9485 10 ; switch. If the NPX context belongs to the current task, nothing happens.
9487 12 ; A trap gate should be placed in IDT entry 7 referring to this routine.
9488 13 ; The DPL of the gate should be 0 to prevent spoofing. The code segment
9489 14 ; must be at privilege level 0.
9491 16 ; The kernel stack is assumed to overlay the TSS and the NPX save area
9492 17 ; is placed at the end of the TSS area.
9494 19 ; A global word variable LAST_NPX_TASK identifies the TSS selector of
9495 20 ; the last task to use the NPX.
9497 002C 22 npx_save_area equ word ptr 44 ; Offset of NPX save area in TSS
9499 ¨¨¨¨ 24 kernal_code segment er public
9501 0000 26 switch_npx_context proc far wc(0)
9503 0000 50 28 push ax ; Save working registers
9505 0002 B8¨¨¨¨ E 30 mov ax,seg last_npx_task ; Get address of id of last NPX task
9506 0005 8ED8 31 mov ds,ax
9507 0007 0F00C8 32 str ax ; Get id of this task
9508 000A 24FC 33 and al,not 3 ; Remove RPL field
9509 000C 0F06 34 clts ; Clear task switched flag
9510 000E FA 35 cli ; No interrupts allowed!
9512 37 ; Last_npx_word cannot change due to other interrupts after this point.
9514 000F 3B060000 E 39 cmp ax,ds:last_npx_task ; See if same task
9515 0013 7412 40 je same_task
9517 0015 87060000 E 42 xchg ax,ds:last_npx_task ; Set new task id and get old one
9518 0019 050800 43 add ax,8 ; Go to TSS alias
9519 001C 8ED8 44 mov ds,ax ; Address TSS of previous NPX task
9520 001E DD362C00 45 fsave ds:npx_save_area ; Save old NPX state
9521 0022 36DD262C00 46 frstor ss:npx_save_area ; Get current NPX state
9523 0027 1F 48 pop ds ; Return to interrupted program
9527 52 switch_npx_context endp
9529 - - - - 54 kernel_code ends
9530 *** WARNING #160, LINE #54, SEGMENT CONTAINS PRIVILEGED INSTRUCTIONS
9534 11.5 Multiprocessor Condiderations
9536 As mentioned in Chapter 8, a bus lock is applied during the testing and
9537 setting of the task busy bit to ensure that two processors do not invoke the
9538 same task at the same time. However, protection traps and conflicting use of
9539 dynamically varying segments or descriptors must be addressed by an
9540 inter-processor synchronization protocol. The protocol can use the
9541 indivisible semaphore operation of the base instruction set. Coordination of
9542 interrupt and trap vectoring must also be addressed when multiple concurrent
9543 processors are operating.
9545 The interrupt bus cycles are locked so no interleaving occurs on those
9546 cycles. Descriptor caching is locked so that a descriptor reference cannot
9547 be altered while it is being fetched.
9549 When a program changes a descriptor that is shared with other processors,
9550 it should broadcast this fact to the other processors. This broadcasting can
9551 be done with an inter-processor interrupt. The handler for this interrupt
9552 must ensure that the segment registers, the LDTR and the TR, are re-loaded.
9553 This happens automatically if the interrupt is serviced by a task switch.
9555 Modification of descriptors of shared segments in multi-processor systems
9556 may require that the on-chip descriptors also be updated. For example, one
9557 processor may attempt to mark the descriptor of a shared segment as
9558 not-present while another is using it. Software has to ensure that the
9559 descriptors in the segment register caches are updated with the new
9560 information. The segment register caches can be updated by a re-entrant
9561 procedure that is invoked by an inter-processor interrupt. The handler must
9562 ensure that the segment registers, the LDTR and the TR, are re-loaded. This
9563 happens automatically if the interrupt is serviced by a task switch.
9568 Shutdown occurs when a severe error condition prevents further processing.
9569 Shutdown is very similar to HLT in that the 80286 stops executing
9570 instructions. The 80286 externally signals shutdown as a Halt bus cycle with
9571 A1=0. The NMI or RESET input will force the 80286 out of shutdown. The INTR
9572 input is ignored during shutdown.
9575 Appendix A 80286 System Initialization
9577 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
9579 $title('Switch the 80286 from Real Address Mode to Protected Mode')
9580 name switch 80286_modes
9581 public idt_desc,gdt_desc
9583 ; Switch the 80286 from real address mode into protected mode.
9584 ; The initial EPROM GDT, IDT, TSS, and LDT (if any) constructed by BLD286
9585 ; will be copied from EPROM into RAM. The RAM areas are defined by data
9586 ; segments allocated as fixed entries in the GDT. The CPU registers for
9587 ; GDT, IDT, TSS, and LDT will be set to point at the RAM-based
9588 ; segments. The base fields in the RAM-based GDT will also be updated to
9589 ; point at the RAM-based segments.
9591 ; This code is used by adding it to the list of object modules given
9592 ; to BLD286. BLD286 must then be told to place the setment
9593 ; init_code at address FFFE10H. Execution of the mode switch code begins
9594 ; after RESET. This happens because the mode switch code will start at
9595 ; physical address FFFFF0H, which is the power up address. This code then
9596 ; sets up RAM copies of the EPROM-based segments before jumping to the
9597 ; initial tsk placed at a fixed GDT entry. After the jump, the CPU
9598 ; executes in the state of the first task defined by BLD286.
9600 ; This code will not use any of the EPROM-based tables directly.
9601 ; Such use would result in the 80286 writing into EPROM to set
9602 ; the A bit. Any use of a GDT or TSS will always be in the RAM copy.
9603 ; The limit and size of the EPROM-based GDT and IDT must be stored at
9604 ; the public symbols idt_desc and gdt_desc. The location commands of BLD286
9605 ; provide this function.
9607 ; Interrupts are disabled during this mode switching code. Full error
9608 ; checking is made of the EPROM-based GDT, IDT, TSS, and LDT to assure
9609 ; they are valid before copying them to RAM. If any of the RAM-based
9610 ; aslias segments are smaller than the EPROM segments they are to hold,
9611 ; halt or shutdown will occur. In general, any exception or NMI will
9612 ; cause shutdown to occur until the first task is invoked.
9614 ; If the RAM segment is larger than the EPROM segment, the RAM segment
9615 ; will be expanded with zeros. If the initial TSS specifies an LDT,
9616 ; the LDT will also be copied into ldt_alias with zero fill if needed.
9617 ; The IPROM-based or RAM-based GDT, IDT, TSS, and LDT segments may be located
9618 ; anywhere in physical memory.
9621 ; Define layout of a descriptor.
9624 limit dw 0 ; Offset of last byte in segment
9625 base_low dw 0 ; Low 16 bits of 24-bit address
9626 base_high db 0 ; High 8 bits of 24-bit address
9627 access db 0 ; Access rights byte
9628 res dw 0 ; Reserved word
9631 ; Define the fixed GDT selector values for the descriptors that
9632 ; define the EPROM-based tables. BLD286 must be instructed to place the
9633 ; appropriate descriptors into the GDT.
9635 gdt_alias equ 1*size desc ; GDT(1) is data segment in RAM for GDT
9636 idt_alias equ 2*size desc ; GDT(2) is data segment in RAM for IDT
9637 start_TSS_alias equ 3*size desc ; GDT(3) is data segment in RAM for TSS
9638 start_task equ 4*size desc ; GDT(4) is TSS for starting task
9639 start_LDT_alias equ 5*size desc ; GDT(5) is data segment in RAM for LDT
9641 ; Define machine status word bit positions.
9643 PE equ 1 ; Protection enable
9644 MP equ 2 ; Monitor processor extension
9645 EM equ 4 ; Emulate processor extension
9647 ; Define particular values of descriptor access rights byte.
9649 DT_ACCESS equ 82H ; Access byte value for an LDT
9650 DS_ACCESS equ 92H ; Access byte value for data segment
9651 ; which is grow up, at level 0, writeable
9652 TSS_ACCESS equ 81H ; Access byte value for an idle TSS
9653 DPL equ 60H ; Privilege level field of access rights
9654 ACCESSED equ 1 ; Define accessed bit
9655 TI equ 4 ; Position of TI bit
9656 TSS_SIZE equ 44 ; Size of a TSS
9657 LDT_OFFSET equ 42 ; Position of LDT in TSS
9658 TIRPL_MASK equ size desc-1 ; TI and RPL field mask
9660 ; Pass control from the power-up address to the mode switch code.
9661 ; The segment containing this code must be at physical address FFFE10H
9662 ; to place the JMP instruction at physical address FFFFF0H. The base
9663 ; address is chosen according to the size of this segment.
9665 init_code segment er
9667 cs_offset equ 0FE10H ; Low 16 bits of starting address
9668 org 0FFF0H-cs_offset; Start at address FFFFF0H
9669 jmp reset_startup ; Do not change CS!
9671 ; Define the template for a temporary GDT used to locate the initial
9672 ; GDT and stack. This data will be copied to location 0.
9673 ; This space is also used for a temporary stack and finally serves
9674 ; as the TSS written into when entering the initial TSS.
9676 org 0 ; Place remaining code below power_up
9678 initial_gdt desc <> ; Filler and null IDT descriptor
9679 gdt_desc desc <> ; Descriptor for EPROM GDT
9680 idt_desc desc <> ; Descriptor for EPROM IDT
9681 temp_desc desc <> ; Temporary descriptor
9683 ; Define a descriptor that will point the GDT at location 0.
9684 ; This descriptor will also be loaded into SS to define the initial
9685 ; protected mode stack segment.
9687 temp_stack desc <end_gdt-initial_gdt-1,0,0,DS_ACCESS,0>
9689 ; Define the TSS descriptor used to allow the task switch to the
9690 ; first task to overwrite this region of memory. The TSS will overlay
9691 ; the initial GDT and stack at location 0.
9693 save_tss desc <end_gdt-initial_gdt-1,0,0,TSS_ACCESS,0>
9695 ; Define the initial stack space and filler for the end of the TSS.
9700 start_pointer label dword
9701 dw 0,start_task ; Pointer to initial task
9703 ; Define template for the task definition list.
9705 task_entry struc ; Define layout of task description
9706 TSS_sel dw ? ; Selector for TSS
9707 TSS_alias dw ? ; Data segment alias for TSS
9708 LDT_alias dw ? ; Data segment alias for LDT if any
9711 task_list task_entry <start_task,start_TSS_alias,start_LDT_alias>
9712 dw 0 ; Terminate list
9715 cli ; No interrupts allowed!
9716 cld ; Use autoincrement mode
9717 xor di,di ; Point ES:DI at physical address 000000H
9720 mov ss,di ; Set stack at end of reserved area
9721 mov sp,end_gdt-initial_gdt
9724 ; Form an adjustment factor from the real CS base of FF0000H to the
9725 ; segment base address assumed by ASM286. Any data reference mode
9726 ; into CS must add an indexing term [BP] to compensate for the difference
9727 ; between the offset generated by ASM286 and the offset required from
9728 ; the base of FF0000H.
9730 start proc ; The value of IP at run time will not be
9731 ; the same as the one used by ASM286!
9732 call start1 ; Get true offset of start1
9735 sub bp, offset start1 ; Subtract ASM286 offset of start1
9736 ; leaving adjustment factor in BP
9737 lidt initial_gdt[bp] ; Setup null IDT to force shutdown
9738 ; on any protection error or interrupt
9740 ; Copy the EPROM-based temporary GDT into RAM.
9742 lea si,initial_gdt[bp] ; Setup pointer to temporary GDT
9744 mov cs,(end_gdt-initial_gdt)/2 ; Set length
9745 rep movs es:word ptr [di],cs:[si]; Put into reserved RAM area
9747 ; Look for 80287 processor extension. Assume all ones will be read
9748 ; if an 80287 is not present.
9750 fninit ; Initialize 80287 if present
9751 mov bx,EM ; Assume no 80287
9752 fstsw ax ; Look at status of 80287
9753 or al,al ; No errors should be present
9754 jnz set_mode ; Jump if no 80287
9756 fsetpm ; Put 80287 into protected mode
9759 ; Switch to protected mode and setup a stack, GDT, and LDT.
9762 smsw ax ; Get current MSW
9763 or ax,PE ; Set PE bit
9764 or ax,bx ; Set NPX status flags
9765 lmsw ax ; nter protected mode!
9766 jmp $+2 ; Clear queue of instructions decoded
9767 ; while in Real Address Mode
9768 ; CPL is now 0, CS still points at
9769 ; FFFE10 in physical memory
9770 lgdt temp_stack[bp] ; Use initial GDT in RAM area
9771 mov ax,temp_stack-initial_gdt ; Setup SS with valid protected mode
9772 mov ss,ax ; selector to the RAM GDT and stack
9773 xor ax,ax ; Set the current LDT to null
9774 lidt ax ; Any references to it will cause
9775 ; an exception causing shutdown
9776 mov ax,save_tss-initial_gdt ; Set initial TSS into the low RAM
9777 ltr ax ; The task switch needs a valid TSS
9779 ; Copy the EPROM-based GDT into the RAM data segment alias.
9780 ; First the descriptor for the RAM data segment must be copied into
9781 ; the temporary GDT.
9783 mov ax,gdt_desc[bp].limit ; Get size of GDT
9784 cmp ax,6*size desc-1 ; Be sure the last entry expected by
9785 ; this code is inside the GDT
9786 jb bad_gdt ; Jump if GDT is not big enough
9788 mov bx,gdt_desc-initial_gdt ; Form selector to EPROM GDT
9789 mov si,gdt_alias ; Get selector of GDT alias
9790 call copy_EPROM_dt ; Copy into EPROM
9791 mov si,idt_alias ; Get selector of IDT alias
9792 mov bx,ldt_desc-initial_gdt ; Indicate EPROM IDT
9794 mov ax,gdt_desc-initial_gdt ; Setup addressing into EPROM GDT
9796 mov bx,gdt_alias ; Get GDT alias data segment selector
9797 lgdt [bx] ; Set GDT to RAM GDT
9798 ; SS and TR remain in low RAM
9800 ; Copy all task's TSS and LDT segments into RAM
9802 lea bx,task_list[bp] ; Define list of tasks to setup
9804 call copy_tasks ; Copy them into RAM
9805 add bx,size task_entry ; Go to next entry
9806 mov ax,cs:[bx].tss_sel ; See if there is another entry
9810 ; With TSS, GDT, and LDT set, startup the initial task!
9812 mov bx,gdt_alias ; Point DS at GDT
9814 mov bx,idt_alias ; Get IDT alias data segment selector
9815 lidt [bx] ; Start the first task!
9816 jmp start_pointer[bp] ; The low RAM area is overwritten with
9817 ; the current CPU context
9819 bad_gdt: ; Wait here if GDT is not big enough
9823 ; Copy the TSS and LDT for the task pointed at by CS:BX.
9824 ; If the task has an LDT it will also be copied down.
9825 ; BX and BP are transparent.
9828 hlt ; Halt here if TSS is invalid
9831 mov si,gdt_alias ; Get addressability to GDT
9833 mov si,cs:[bx].tss_alias ; Get selector for TSS alias
9834 mov es,si ; Point ES at alias data segment
9835 lsl ax,si ; Get length of TSS alias
9836 mov si,cs:[bx].tss_sel ; Get TSS selector
9837 lar dx,si ; Get alias access rights
9838 jnz bad_tss ; Jump if invalid reference
9840 mov dl,dh ; Save TSS descriptor access byte
9841 and dh,not DPL ; Ignore privilege
9842 cmp dh,TSS_ACCESS ; See if TSS
9843 jnz bad_tss ; Jump if not
9845 lsl cs,si ; Get length of EPROM based TSS
9846 cmp cs,TSS_SIZE-1 ; Verify it is of proper size
9847 jb bad_tss ; Jump if it is not big enough
9849 ; Setup for moving the EPROM-based TSS to RAM
9852 mov [si].access,DS_ACCESS ; Make TSS into data segment
9853 mov ds,si ; Point DS at EPROM TSS
9854 call copy_with_fill ; Copy DS segment to ES with zero fill
9855 ; CX has copy count, AX-CX fill count
9857 ; Set the GDT TSS limit and base address to the RAM values
9859 mov ax,gdt_alias ; Restore GDT addressing
9862 mov di,cs:[bx].tss_sel ; Get TSS selector
9863 mov si,cs:[bx].tss_alias ; Get RAM alias selector
9865 movsw ; Copy low 16 bits of adress
9866 lodsw ; Get high 8 bits of address
9867 mov ah,dl ; Mark as TSS descriptor
9868 stosw ; Fill in high address and access bytes
9869 movsw ; Copy reserved word
9871 ; See if a valid LDT is specified for the startup task
9872 ; If so then copy the EPROM version into the RAM alias.
9874 mov ds,cs:[bx].tss_alias ; Address TSS to get LDT
9875 mov si,ds:word ptr LDT_OFFSET
9876 and si,not TIRPL_MASK ; Ignore TI and RPL
9877 jz no_ldt ; Skip this if no LDT used
9879 push si ; Save LDT selector
9880 lar dx,si ; Test descriptor
9881 jnz bad_ldt ; Jump if invalid selector
9883 mov dl,dh ; Save LDT descriptor access byte
9884 and dh,not DPL ; Ignore privilege
9885 cmp dh, DT_ACCESS ; Be sure it is an LDT descriptor
9886 jne bad_ldt ; Jump if invalid
9888 mov es:[si].access,DS_ACCESS ; Mark LDT as data segment
9889 mov ds,si ; Point DS at EPROM LDT
9890 lsl ax,si ; Get LDT limit
9891 call test_dt_limit ; Verify it is valid
9892 mov cx,ax ; Save for later
9895 ; Examine the LDT alias segment and, if good, copy to RAM
9897 mov si,cs:[bx].ldt_alias ; Get ldt alias selector
9898 mov es,si ; Point ES at alias segment
9899 lsl ax,si ; Get length of alias segmewnt
9900 call test_dt_limit ; Verify it is valid
9901 call copy_with_fill ; Copy LDT into RAM alias segment
9903 ; Set the LDT limit and base address to the RAM copy of the LDT.
9905 mov si,cs:[bx].ldt_alias ; Restore LDT alias selector
9906 pop di ; Restore LDT selector
9907 mov ax,gdt_alias ; Restore GDT addressing
9910 movsw ; Move the RAM LDT limit
9911 movsw ; Move the low 16 bits across
9912 lodsw ; Get the high 8 bits
9913 mov ah,dl ; Set high address and access rights
9914 stosw ; Copy reserved word
9919 hit ; Halt here if LDT is invalid
9923 ; Test the descriptor table size in AX to verify that it is an
9924 ; even number of descriptors in length.
9928 push ax ; Save length
9929 end al,7 ; Look at low order bits
9930 cmp al,7 ; Must be all ones
9931 pop ax ; Restore length
9941 ; Copy the EPROM DT at selector BX in the temporary GDT to the alias
9942 ; data segment at selector SI. Any improper descriptors or limits
9943 ; will cause shutdown!
9947 mov ax,ss ; Point ES:DI at temporary descriptor
9949 mov es:[bx].access,DS_ACCESS ; Mark descriptor as a data segment
9950 mov es:[bx].res,0 ; Clear reserved word
9951 lsl ax,bx ; Get limit of EPROM DT
9952 mov cx,ax ; Save for later
9953 call test_dt_limit ; Verify it is a proper limit
9954 mov di,gdt_desc-initial_gdt ; Address EPROM GDT in DS
9956 mov di,temp_desc-initial_gdt ; Get selector for temporary descriptor
9957 push di ; Save offset for later use as selector
9958 lodsw ; Get alias segment size
9959 call test_dt_limit ; Verify it is an even multiple of
9960 ; descriptors in length
9961 stosw ; Put length into temporary
9962 movsw ; Copy remaining entries into temporary
9965 pop es ; ES now points at the GDT alias area
9966 mov ds,bx ; DS now points at EPROM DT as data
9967 ; Copy segment ot alias with zero fill
9968 ; CX is copy count, AX-CX is fill count
9969 ; Fall into copy_with_fill
9974 ; Copy the segment at DS to the segment at ES for length CX.
9975 ; Fill th end with AX-CX zeros.s Use word operations for speed but
9976 ; allow odd byte operations.
9980 xor si,si ; Start at beginning of segments
9982 sub ax,cx ; Form fill count
9983 add cs,1 ; Convert laimit to count
9984 rcr cs,1 ; Allow full 64K move
9985 rep movsw ; Copy DT into alias area
9986 xchg ax,cx ; Get fill count and zero AX
9987 jnc even_copy ; Jump if even byte count on copy
9989 movsb ; Copy odd byte
9991 jz exit_copy ; Exit if no fill
9993 stosb ; Even out the segment offset
9994 dec cx ; Adjust remaining fill count
9996 shr cx,1 ; Form word count on fill
9997 rep stosw ; Clear unused words at end
9998 jnc exit_copy ; Exit if no odd byte remains
10000 stosb ; Clear last odd byte
10004 copy_with_fill endp
10013 Appendix B The 80286 Instruction Set
10015 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
10017 This section presents the 80286 instruction set using Intel's ASM286
10018 notation. All possible operand types are shown. Instructions are organized
10019 alphabetically according to generic operations. Within each operation, many
10020 different instructions are possible depending on the operand. The pages are
10021 presented in a standardized format, the elements of which are described in
10022 the following paragraphs.
10026 This column gives the complete object code produced for each form of the
10027 instruction. Where possible, the codes are given as hexadecimal bytes,
10028 presented in the order in which they will appear in memory. Several
10029 shorthand conventions are used for the parts of instructions which specify
10030 operands. These conventions are as follows:
10032 /n: (n is a digit from 0 through 7) A ModRM byte, plus a possible immediate
10033 and displacement field follow the opcode. See figure B-1 for the encoding
10034 of the fields. The digit n is the value of the REG field of the ModRM byte.
10035 To obtain the possible hexadecimal values for /n, refer to column n of table
10036 B-1. Each row gives a possible value for the effective address operand
10037 to the instruction. The entry at the end of the row indicates whether the
10038 effective address operand is a register or memory; if memory, the entry
10039 indicates what kind of indexing and/or displacement is used. Entries with
10040 D8 or D16 signify that a one-byte or two-byte displacement quantity
10041 immediately follows the ModRM and optional immediate field bytes. The
10042 signed displacement is added to the effective address offset.
10044 /r: A ModRM byte that contains both a register operand and an effective
10045 address operand, followed by a possible immediate and displacement field.
10046 See figure B-2 for the encoding of the fields. The ModRM byte could be any
10047 value appearing in table B-1. The column determines which register
10048 operand was selected; the row determines the form of effective address. If
10049 the row entry mentions D8 or D16, then a one-byte or two-byte displacement
10050 follows, as described in the previous paragraph.
10052 cb: A one-byte signed displacement in the range of -128 to +127 follows the
10053 opcode. The displacement is sign-extended to 16 bits, and added modulo 65536
10054 to the offset of the instruction FOLLOWING this instruction to obtain the
10057 cw: A two-byte displacement is added modulo 65536 to the offset of the
10058 instruction FOLLOWING this instruction to obtain the new IP value.
10060 cd: A two-word pointer which will be the new CS:IP value. The offset is
10061 given first, followed by the selector.
10063 db: An immediate byte operand to the instruction which follows the opcode
10064 and ModRM bytes. The opcode determines if it is a signed value.
10066 dw: An immediate word operand to the instruction which follows the opcode
10067 and ModRM bytes. All words are given in the 80286 with the low-order byte
10070 +rb: A register code from 0 through 7 which is added to the hexadecimal byte
10071 given at the left of the plus sign to form a single opcode byte. The codes
10072 are: AL=0, CL=1, DL=2, BL=3, AH=4, CH=5, DH=6, and BH=7.
10074 +rw: A register code from 0 through 7 which is added to the hexadecimal byte
10075 given at the left of the plus sign to form a single opcode byte. The codes
10076 are: AX=0, CX=1, DX=2, BX=3, SP=4, BP=5, SI=6, and DI=7.
10079 Table B-1. ModRM Values
10082 Rb = AL CL DL BL AH CH DH BH
10083 Rw = AX CX DX BX SP BP SI DI
10084 REG = 0 1 2 3 4 5 6 7
10086 ModRM values Effective address
10088 00 08 10 18 20 28 30 38 [BX + SI]
10089 01 09 11 19 21 29 31 39 [BX + DI]
10090 02 0A 12 1A 22 2A 32 3A [BP + SI]
10091 03 0B 13 1B 23 2B 33 3B [BP + DI]
10092 mod=00 04 0C 14 1C 24 2C 34 3C [SI]
10093 05 0D 15 1D 25 2D 35 3D [DI]
10094 06 0E 16 1E 26 2E 36 3E D16 (simple var)
10095 07 0F 17 1F 27 2F 37 3F [BX]
10097 40 48 50 58 60 68 70 78 [BX + SI] + D8
10098 D8 denotes an 8-bit displacement following the ModRM byte that is
10099 sign-extended and added to the index.
10103 41 49 51 59 61 69 71 79 [BX + DI] + D8
10104 42 4A 52 5A 62 6A 72 7A [BP + SI] + D8
10105 43 4B 53 5B 63 6B 73 7B [BP + DI] + D8
10106 mod=01 44 4C 54 5C 64 6C 74 7C [SI] + D8
10107 45 4D 55 5D 65 6D 75 7D [DI] + D8
10108 46 4E 56 5E 66 6E 76 7E [BP] + D8
10109 Default segment register is SS for effective addresses containing a BP
10110 index; DS is for other memory effective addresses.
10114 47 4F 57 5F 67 6F 77 7F [BX] + D8
10116 80 88 90 98 A0 A8 B0 B8 [BX + SI] + D16
10117 D16 denotes the 16-bit displacement following the ModRM byte that is
10118 added to the index.
10122 81 89 91 99 A1 A9 B1 B9 [BX + DI] + D16
10123 82 8A 92 9A A2 AA B2 BA [BP +SI] + D16
10124 83 8B 93 9B A3 AB B3 BB [BP + DI] + D16
10125 mod=10 84 8C 94 9C A4 AC B4 BC [SI] + D16
10126 85 8D 95 9D A5 AD B5 BD [DI] + D16
10127 86 8E 96 9E A6 AE B6 BE [BP] + D16
10128 Default segment register is SS for effective addresses containing a BP
10129 index; DS is for other memory effective addresses.
10133 87 8F 97 9F A7 AF B7 BF [BX] + D16
10135 C0 C8 D0 D8 E0 E8 F0 F8 Ew=AX Eb=AL
10136 C1 C9 D1 D9 E1 E9 F1 F9 Ew=CX Eb=CL
10137 C2 CA D2 DA E2 EA F2 FA Ew=DX Eb=DL
10138 C3 CB D3 DB E3 EB F3 FB Ew=BX Eb=BL
10139 mod=11 C4 CC D4 DC E4 EC F4 FC Ew=SP Eb=AH
10140 C5 CD D5 DD E5 ED F5 FD Ew=BP Eb=CH
10141 C6 CE D6 DE E6 EE F6 FE Ew=SI Eb=DH
10142 C7 CF D7 DF E7 EF F7 FF Ew=DI Eb=BH
10146 Figure B-1. /n Instruction Byte Format
10148 pp/n Instruction Byte Format
10149 ‚����Ð�������Ð�������Ð������������Ð������������Ð������������Ð������������ƒ
10150 € mod� n � r/m � imm. low
10151 Opcode indicates presence and size of immediate field. � imm. high
10152 Opcode indicates presence and size of immediate field. � disp-low � disp-high €
10153 „����¤�������¤�������¤������������¤������������¤������������¤������������…
10154 7 6 5 4 3 2 1 0 7 0 7 0 7 0 7 0
10156 "mod" Field Bit Assignments
10157 ‚����������Ð�������������������������������������������������������������ƒ
10158 € mod � Displacement €
10159 †����������Ï�������������������������������������������������������������‡
10161 Except if mod = 00 and r/m = 110 then EA = disp-high:disp-low., disp-low and disp-high are absent €
10162 € 01 �DISP = disp-low sign-extended to 16-bit, disp-high is absent €
10163 € 10 �DISP = disp-high: disp-low €
10164 € 11 �r/m is treated as a "reg" field €
10165 „����������¤�������������������������������������������������������������…
10167 "r/m" Field Bit Assignments
10168 ‚������������������������������������Ð�����������������������������������ƒ
10169 € r/m � Operand Address €
10170 †������������������������������������Ï�����������������������������������‡
10171 € 000 � (BX) + (SI) + DISP €
10172 € 001 � (BX) + (DI) + DISP €
10173 € 010 � (BP) + (SI) + DISP €
10174 € 011 � (BP) + (DI) + DISP €
10175 € 100 � (SI) + DISP €
10176 € 101 � (DI) + DISP €
10177 € 110 � (BP) + DISP
10178 Except if mod = 00 and r/m = 110 then EA = disp-high:disp-low. €
10179 € 111 � (BX) + DISP €
10180 „������������������������������������¤�����������������������������������…
10181 DISP follows 2nd byte of instruction (before data if required).
10184 Figure B-2. /r Instruction Byte Format
10186 /r Instruction Byte Format
10187 ‚����Ð�������Ð�������Ð������������Ð������������Ð������������Ð������������ƒ
10188 € mod� r � r/m � imm. low
10189 Opcode indicates presence and size of immediate field. � imm. high
10190 Opcode indicates presence and size of immediate field. � disp-low � disp-high €
10191 „����¤�������¤�������¤������������¤������������¤������������¤������������…
10192 7 6 5 4 3 2 1 0 7 0 7 0 7 0 7 0
10194 "mod" Field Bit Assignments
10195 ‚����������Ð�������������������������������������������������������������ƒ
10196 € mod � Displacement €
10197 †����������Ï�������������������������������������������������������������‡
10199 Except if mod = 00 and r/m = 110 then EA = disp-high:disp-low., disp-low and disp-high are absent €
10200 € 01 �DISP = disp-low sign-extended to 16-bit, disp-high is absent €
10201 € 10 �DISP = disp-high: disp-low €
10202 € 11 �r/m is treated as a "reg" field €
10203 „����������¤�������������������������������������������������������������…
10205 "r" Field Bit Assignments
10206 ‚�����������������������Ð�����������������������Ð������������������������ƒ
10207 € 16-Bit (w = 1) � 6-Bit (w = 0) � Segment €
10208 †�����������������������Ï�����������������������Ï������������������������‡
10209 € 000 AX � 000 AL � 00 ES €
10210 € 001 CX � 001 CL � 01 CS €
10211 € 010 DX � 010 DL � 10 SS €
10212 € 011 BX � 011 BL � 11 DS €
10213 € 100 SP � 100 AH � €
10214 € 101 BP � 101 CH � €
10215 € 110 SI � 110 DH � €
10216 € 111 DI � 111 BH � €
10217 „�����������������������¤�����������������������¤������������������������…
10219 "r/m" Field Bit Assignments
10220 ‚������������������������������������Ð�����������������������������������ƒ
10221 € r/m � Operand Address €
10222 †������������������������������������Ï�����������������������������������‡
10223 € 000 � (BX) + (SI) + DISP €
10224 € 001 � (BX) + (DI) + DISP €
10225 € 010 � (BP) + (SI) + DISP €
10226 € 011 � (BP) + (DI) + DISP €
10227 € 100 � (SI) + DISP €
10228 € 101 � (DI) + DISP €
10229 € 110 � (BP) + DISP
10230 Except if mod = 00 and r/m = 110 then EA = disp-high:disp-low. €
10231 € 111 � (BX) + DISP €
10232 „������������������������������������¤�����������������������������������…
10233 DISP follows 2nd byte of instruction (before data if required).
10238 This column gives the instruction mnemonic and possible operands. The type
10239 of operand used will determine the opcode and operand encodings. The
10240 following entries list the type of operand which can be encoded in the
10241 format shown in the instruction column. The Intel convention is to place
10242 the destination operand as the left hand operand. Source-only operands
10243 follow the destination operand.
10245 In many cases, the same instruction can be encoded several ways. It is
10246 recommended that you use the shortest encoding. The short encodings are
10247 provided to save memory space.
10249 cb: a destination instruction offset in the range of 128 bytes before the
10250 end of this instruction to 127 bytes after the end of this instruction.
10252 cw: a destination offset within the same code segment as this instruction.
10253 Some instructions allow a short form of destination offset. See cb type for
10256 cd: a destination address, typically in a different code segment from this
10257 instruction. Using the cd: address form with call instructions saves the
10258 code segment selector.
10260 db: a signed value between -128 and +127 inclusive which is an operand of
10261 the instruction. For instructions in which the db is to be combined in some
10262 way with a word operand, the immediate value is sign-extended to form a
10263 word. The upper byte of the word is filled with the topmost bit of the
10266 dw: an immediate word value which is an operand of the instruction.
10268 eb: a byte-sized operand. This is either a byte register or a (possibly
10269 indexed) byte memory variable. Either operand location may be encoded in the
10270 ModRM field. Any memory addressing mode may be used.
10272 ed: a memory-based pointer operand. Any memory addressing mode may be used.
10273 Use of a register addressing mode will cause exception 6.
10275 ew: a word-sized operand. This is either a word register or a (possibly
10276 indexed) word memory variable. Either operand location may be encoded in the
10277 ModRM field. Any memory addressing mode may be used.
10279 m: a memory location. Operands in registers do not have a memory address.
10280 Any memory addressing mode may be used. Use of a register addressing mode
10281 will cause exception 6.
10283 mb: a memory-based byte-sized operand. Any memory addressing mode may be
10286 mw: a memory-based word operand. Any memory addressing mode may be used.
10288 rb: one of the byte registers AL, CL, DL, BL, AH, CH, DH, or BH; rb has the
10289 value 0,1,2,3,4,5,6, and 7, respectively.
10291 rw: one of the word registers AX, CX, DX, BX, SP, BP, SI, or DI; rw has the
10292 value 0,1,2,3,4,5,6, and 7, respectively.
10294 xb: a simple byte memory variable without a base or index register. MOV
10295 instructions between AL and memory have this optimized form if no indexing
10298 xw: a simple word memory variable without a base or index register. MOV
10299 instructions between AX and memory have this optimized form if no indexing
10305 This column gives the number of clock cycles that this form of the
10306 instruction takes to execute. The amount of time for each clock cycle is
10307 computed by dividing one microsecond by the number of MHz at which the 80286
10308 is running. For example, a 10-MHz 80286 (with the CLK pin connected to
10309 a 20-MHz crystal) takes 100 nanoseconds for each clock cycle.
10311 Add one clock to instructions that use the base plus index plus
10312 displacement form of addressing. Add two clocks for each 16-bit memory based
10313 operand reference located on an odd physical address. Add one clock for each
10314 wait state added to each memory read. Wait states inserted in memory writes
10315 or instruction fetches do not necessarily increase execution time.
10317 The clock counts establish the maximum execution rate of the 80286. With no
10318 delays in bus cycles, the actual clock count of an 80286 program will
10319 average 5-10% more than the calculated clock count due to instruction
10320 sequences that execute faster than they can be fetched from memory.
10322 Some instruction forms give two clock counts, one unlabelled and one
10323 labelled. These counts indicate that the instruction has two different clock
10324 times for two different circumstances. Following are the circumstances for
10325 each possible label:
10327 mem: The instruction has an operand that can either be a register or a
10328 memory variable. The unlabelled time is for the register; the mem time is
10329 for the memory variable. Also, one additional clock cycle is taken for
10330 indexed memory variables for which all three possible indices (base
10331 register, index register, and displacement) must be added.
10333 noj: The instruction involves a conditional jump or interrupt. The
10334 unlabelled time holds when the jump is made; the noj time holds when the
10337 pm: If the instruction takes more time to execute when the 80286 is in
10338 Protected Mode. The unlabelled time is for Real Address Mode; the pm time is
10339 for Protected Mode.
10344 This is a concise description of the operation performed for this form of
10345 the instruction. More details are given in the "Operation" section that
10346 appears later in this chapter.
10351 This is a list of the flags that are set to a meaningful value by the
10352 instruction. If a flag is always set to the same value by the instruction,
10353 the value is given ("=0" or "=1") after the flag name.
10358 This is a list of the flags that have an undefined (meaningless) setting
10359 after the instruction is executed.
10361 All flags not mentioned under "Flags Modified" or "Flags Undefined" are
10362 unchanged by the instruction.
10367 This section fully describes the operation performed by the instruction.
10368 For some of the more complicated instructions, suggested usage is also
10372 Protected Mode Exceptions
10374 The possible exceptions involved with this instruction when running under
10375 the 80286 Protected Mode are listed below. These exceptions are abbreviated
10376 with a pound sign (#) followed by two capital letters and an optional error
10377 code in parenthesis. For example, #GP(0) denotes the general protection
10378 exception with an error code of zero. The next section describes all of the
10379 80286 exceptions and the machine state upon entry to the exception.
10381 If you are an applications programmer, consult the documentation provided
10382 with your operating system to determine what actions are taken by the system
10383 when exceptions occur.
10386 Real Address Mode Exceptions
10388 Since less error checking is performed by the 80286 when it is in Real
10389 Address Mode, there are fewer exceptions in this mode. One exception that is
10390 possible in many instructions is #GP(0). Exception 13 is generated whenever
10391 a word operand is accessed from effective address 0FFFFH in a segment. This
10392 happens because the second byte of the word is considered located at
10393 location 10000H, not at location 0, and thus exceeds the segment's
10394 addressability limit.
10397 Protection Exceptions
10399 In parallel with the execution of instructions, the protected-mode 80286
10400 checks all memory references for validity of addressing and type of access.
10401 Violation of the memory protection rules built into the processor will cause
10402 a transfer of program control to one of the interrupt procedures described
10403 in this section. The interrupts have dedicated positions within the
10404 Interrupt Descriptor Table, which is shown in table B-2. The interrupts are
10405 referenced within the instruction set pages by a pound sign (#) followed by
10406 a two-letter mnemonic and the optional error code in parenthesis.
10409 Table B-2. Protection Exceptions of the 80286
10411 Abbreviation Interrupt Number Description
10413 #UD 6 Undefined Opcode
10414 #NM 7 No Math Unit Available
10416 #MP 9 Math Unit Protection Fault
10417 #TS 10 Invalid Task State Segment
10420 #GP 13 General Protection
10426 Some exceptions cause the 80286 to pass a 16-bit error code to the
10427 interrupt procedure. When this happens, the error code is the last item
10428 pushed onto the stack before control is tranferred to the interrupt
10429 procedure. If stacks were switched as a result of the interrupt (causing a
10430 privilege change or task switch), the error code appears on the interrupt
10431 procedure's stack, not on the stack of the task that was interrupted.
10433 The error code generally contains the selector of the segment that caused
10434 the protection violation. The RPL field (bottom two bits) of the error code
10435 does not, however, contain the privilege level. Instead, it contains the
10436 following information:
10438 Ž Bit 0 contains the value 1 if the exception was detected during an
10439 interrupt caused by an event external to the program (i.e., an external
10440 interrupt, a single step, a processor extension not-present exception,
10441 or a processor extension segment overrun). Bit 0 is 0 if the exception
10442 was detected while processing the regular instruction stream, even if
10443 the instruction stream is part of an external interrupt handling
10444 procedure or task. If bit 0 is set, the instruction pointed to by the
10445 saved CS:IP address is not responsible for the error. The current task
10446 can be restarted unless this is exception 9.
10448 Ž Bit 1 is 1 if the selector points to the Interrupt Descriptor Table.
10449 In this case, bit 2 can be ignored, and bits 3-10 contain the index
10452 Ž Bit 1 is 0 if the selector points to the Global or Local Descriptor
10453 Tables. In this case, bits 2-15 have their usual selector
10454 interpretation: bit 2 selects the table (1=Local, 0=Global), and
10455 bits 3-15 are the index into the table.
10457 In some cases the 80286 chooses to pass an error code with no information
10458 in it. In these cases, all 16 bits of the error code are zero.
10460 The existence and type of error codes are described under each of the
10461 following individual exceptions.
10464 #DF 8 Double Fault (Zero Error Code)
10466 This exception is generated when a second exception is detected while the
10467 processor is attempting to transfer control to the handler for an exception.
10468 For instance, it is generated if the code segment containing the exception
10469 handler is marked not present. It is also generated if invoking the
10470 exception handler causes a stack overflow.
10472 This exception is not generated during the execution of an exeception
10473 handler. Faults detected within the instruction stream are handled by
10474 regular exceptions.
10476 The error code is normally zero. The saved CS:IP will point at the
10477 instruction that was attempting to execute when the double fault occurred.
10478 Since the error code is normally zero, no information on the source of the
10479 exception is available. Restart is not possible.
10481 The "double fault" exception does not occur when detecting a new exception
10482 while trying to invoke handlers for the following exceptions: 1, 2, 3, 4, 5,
10485 If another exception is detected while attempting to perform the double
10486 fault exception, the 80286 will enter shutdown (see section 11.5).
10489 #GP 13 General Protection (Selector or Zero Error Code)
10491 This exception is generated for all protection violations not covered by
10492 the other exceptions in this section. Examples of this include:
10494 1. An attempt to address a memory location by using an offset that
10495 exceeds the limit for the segment involved.
10497 2. An attempt to jump to a data segment.
10499 3. An attempt to load SS with a selector for a read-only segment.
10501 4. An attempt to write to a read-only segment.
10503 5. Exceeding the maximum instruction length of 10 bytes.
10505 If #GP occurred while loading a descriptor, the error code passed contains
10506 the selector involved. Otherwise, the error code is zero.
10508 If the error code is not zero, the instruction can be restarted if the
10509 erroneous condition is rectified. If the error code is zero either a limit
10510 violation, a write protect violation, or an illegal use of invalid segment
10511 register occurred. An invalid segment register contains the values 0-3. A
10512 write protect fault on ADC, SBB, RCL, RCR, or XCHG is not restartable.
10515 #MF 16 Math Fault (No Error Code)
10517 This exception is generated when the numeric processor extension (the
10518 80287) detects an error signalled by the ERROR input pin leading from the
10519 80287 to the 80286. The ERROR pin is tested at the beginning of most
10520 floating point instructions, and when a WAIT instruction is executed with
10521 the EM bit of the Machine Status Word set to 0 (i.e., no emulation of the
10522 math unit). The floating point instructions that do not cause the ERROR pin
10523 to be tested are FNCLEX, FNINIT, FSETPM, FNSTCW, FNSTSW, FNSAVE, and
10526 If the handler corrects the error condition causing the exception, the
10527 floating point instruction that caused #MF can be restarted. This is not
10528 accomplished by IRET, however, since the fault occurs at the floating point
10529 instruction that follows the offending instruction. Before restarting the
10530 numeric instruction, the handler must obtain from the 80287 the address of
10531 the offending instruction and the address of the optional numeric operand.
10534 #MP 9 Math Unit Protection Fault (No Error Code)
10536 This exception is generated if the numeric operand is larger than one word
10537 and has the second or subsequent words outside the segment's limit. Not all
10538 math addressing errors cause exception 9. If the effective address of an
10539 ESCAPE instruction is not in the segment's limit, or if a write is
10540 attempted on a read-only segment, or if a one-word operand violates a
10541 segment limit, exception 13 will occur.
10543 The #MP exception occurs during the execution of the numeric instruction by
10544 the 80287. Thus, the 80286 may be in an unrelated instruction stream at the
10545 time. Exception 9 may occur in a task unrelated to the task that executed
10546 the ESC instruction. The operating system should keep track of which task
10547 last used the NPX (see section 11.4).
10549 The offending floating point instruction cannot be restarted; the task
10550 which attempted to execute the offending numeric instruction must be
10551 aborted. However, if exception 9 interrupted another task, the interrupted
10552 task may be restarted.
10554 The exception 9 handler must execute FNINIT before executing any ESCAPE or
10558 #NM 7 No Math Unit Available (No Error Code)
10560 This exception occurs when any floating point instruction is executed while
10561 the EM bit or the TS bit of the Machine Status Word is 1. It also occurs
10562 when a WAIT instruction is encountered and both the MP and TS bits of the
10563 Machine Status Word are 1.
10565 Depending on the setting of the MSW bits that caused this exception, the
10566 exception handler could provide emulation of the 80287, or it could perform
10567 a context switch of the math processor to prepare it for use by another
10570 The instruction causing #NM can be restarted if the handler performs a
10571 numeric context switch. If the handler provided emulation of the math unit,
10572 it should advance the return pointer beyond the floating point instruction
10576 #NP 11 Not Present (Selector Error Code)
10578 This exception occurs when CS, DS, ES, or the Task Register is loaded with
10579 a descriptor that is marked not present but is otherwise valid. It can occur
10580 in an LLDT instruction, but the #NP exception will not occur if the
10581 processor attempts to load the LDT register during a task switch. A
10582 not-present LDT encountered during a task switch causes the #TS exception.
10584 The error code passed is the selector of the descriptor that is marked not
10587 Typically, the Not Present exception handler is used to implement a virtual
10588 memory system. The operating system can swap inactive memory segments to a
10589 mass-storage device such as a disk. Applications programs need not be told
10590 about this; the next time they attempt to access the swapped-out memory
10591 segment, the Not Present handler will be invoked, the segment will be
10592 brought back into memory, and the offending instruction within the
10593 applications program will be restarted.
10595 If #NP is detected on loading CS, DS, or ES in a task switch, the exception
10596 occurs in the new task, and the IRET from the exception handler jumps
10597 directly to the next instruction in the new task.
10599 The Not Present exception handler must contain special code to complete the
10600 loading of segment registers when #NP is detected in loading the CS or DS
10601 registers in a task switch and a trap or interrupt gate was used. The DS and
10602 ES registers have been loaded but their descriptors have not been loaded.
10603 Any memory reference using the segment register may cause exception 13. The
10604 #NP exception handler should execute code such as the following to ensure
10605 full loading of the segment registers:
10612 #SS 12 Stack Fault (Selector or Zero Error Code)
10614 This exception is generated when a limit violation is detected in
10615 addressing through the SS register. It can occur on stack-oriented
10616 instructions such as PUSH or POP, as well as other types of memory
10617 references using SS such as MOV AX,[BP+28]. It also can occur on an ENTER
10618 instruction when there is not enough space on the stack for the indicated
10619 local variable space, even if the stack exception is not triggered by
10620 pushing BP or copying the display stack. A stack exception can therefore
10621 indicate a stack overflow, a stack underflow or a wild offset. The error
10624 #SS is also generated on an attempt to load SS with a descriptor that is
10625 marked not present but is otherwise valid. This can occur in a task switch,
10626 an inter-level call, an inter-level return, a move to the SS instruction or
10627 a pop to the SS instruction. The error code will be non-zero.
10629 #SS is never generated when addressing through the DS or ES registers even
10630 if the offending register points to the same segment as the SS register.
10632 The #SS exception handler must contain special code to complete the loading
10633 of segment registers. The DS and ES registers will not be fully loaded if a
10634 not-present condition is detected while loading the SS register. Therefore,
10635 the #SS exception handler should execute code such as the following to
10636 insure full loading of the segment registers:
10643 Generally, the instruction causing #SS can be restarted, but there is one
10644 special case when it cannot: when a PUSHA or POPA instruction attempts to
10645 wrap around the 64K boundary of a stack segment. This condition is
10646 identified by the value of the saved SP, which can be either 0000H, 0001H,
10650 #TS 10 Invalid Task State Segment (Selector Error Code)
10652 This exception is generated during a task switch when the new task state
10653 segment is invalid, that is, when a task state segment is too small; when
10654 the LDT indicated in a TSS is invalid or not present; when the SS, CS, DS,
10655 or ES indicated in a TSS are invalid (task switch); when the back link in a
10656 TSS is invalid (inter-task IRET).
10658 #TS is not generated when the SS, CS, DS, or ES back link or privileged
10659 stack selectors point to a descriptor that is not present but otherwise is
10660 valid. #NP is generated in these cases.
10662 The error code passed to the exception handler contains the selector of the
10663 offending segment, which can either be the Task State Segment itself, or a
10664 selector found within the Task State Segment.
10666 The instruction causing #TS can be restarted.
10668 #TS must be handled through a task gate.
10670 The exception handler must reset the busy bit in the new TSS.
10673 #UD 6 Undefined Opcode (No Error Code)
10675 This exception is generated when an invalid operation code is detected in
10676 the instruction stream. Following are the cases in which #UD can occur:
10678 1. The first byte of an instruction is completely invalid (e.g., 64H).
10680 2. The first byte indicates a 2-byte opcode and the second byte is
10681 invalid (e.g., 0FH followed by 0FFH).
10683 3. An invalid register is used with an otherwise valid opcode (e.g., MOV
10686 4. An invalid opcode extension is given in the REG field of the ModRM
10687 byte (e.g., 0F6H /1).
10689 5. A register operand is given in an instruction that requires a memory
10690 operand (e.g., LGDT AX).
10692 Since the offending opcode will always be invalid, it cannot be restarted.
10693 However, the #UD handler might be coded to implement an extension of the
10694 80286 instruction set. In that case, the handler could advance the return
10695 pointer beyond the extended instruction and return control to the program
10696 after the extended instruction is emulated. Any such extensions may be
10697 incompatible with the 80386.
10700 Privilege Level and Task Switching on the 80286
10702 The 80286 supports many of the functions necessary to implement a
10703 protected, multi-tasking operating system in hardware. This support is
10704 provided not by additional instructions, but by extension of the semantics
10705 of 8086/8088 instructions that change the value of CS:IP.
10707 Whenever the 80286 performs an inter-segment jump, call, interrupt, or
10708 return, it consults the Access Rights (AR) byte found in the descriptor
10709 table entry of the selector associated with the new CS value. The AR byte
10710 determines whether the long jump being made is through a gate, or is a task
10711 switch, or is a simple long jump to the same privilege level. Table B-3
10712 lists the possible values of the AR byte. The "privilege" headings at the
10713 top of the table give the Descriptor Privilege Level, which is referred to
10714 as the DPL within the instruction descriptions.
10716 Each of the CALL, INT, IRET, JMP, and RET instructions contains on its
10717 instruction set pages a listing of the access rights checking and actions
10718 taken to implement the instruction. Instructions involving task switches
10719 contain the symbol SWITCH_TASKS, which is an abbreviation for the following
10720 list of checks and actions:
10723 Locked set AR byte of new TSS descriptor to Busy TSS (Bit 1 = 1)
10724 Current TSS cache must be valid with limit � 41 else #TS (error code will
10725 be new TSS, but back link points at old TSS)
10726 Save machine state in current TSS
10727 If nesting tasks, set the new TSS link to the current TSS selector
10728 Any exception will be in new context Else set the AR byte of current TSS
10729 descriptor to Available TSS (Bit 1 = 0)
10730 Set the current TR to selector, base and limit of new TSS
10731 New TSS limit � 43 else #TS (new TSS)
10732 Set all machine registers to values from new TSS without loading
10733 descriptors for DS, ES, CS, SS, LDT
10734 Clear valid flags for LDT, SS, CS, DS, ES (not valid yet)
10735 If nesting tasks, set the Nested Task flag to 1
10736 Set the Task Switched flag to 1
10737 LDT from the new TSS must be within GDT talbe limits else #TS(LDT)
10738 AR byte from LDT descriptor must specifiy LDT segment else #TS(LDT)
10739 AR byte from LDT descriptor must indicate PRESENT else #TS(LDT)
10740 Load LDT cache with new LDT descriptor and set valid bit
10741 Set CPL to the RPL of the CS selector in the new TSS
10742 If new stack selector is null #TS(SS)
10743 SS selector must be within its descriptor table limits else #TS(SS)
10744 SS selector RPL must be equal to CPL else #TS(SS)
10745 DPL of SS descriptor must equal to CPL else #TS(SS)
10746 SS descriptor AR byte must indicate writable data segment else #TS(SS)
10747 SS descriptor AR byte must indicate PRESENT else #TS(SS)
10748 Load SS cache with new stack segment and set valid bit
10749 New CS selector must not be null else #TS(SS)
10750 CS selector must be within its descriptor table limits else #TS(SS)
10751 CS descriptor AR byte must indicate code segment else #TS(SS)
10752 If non-conforming then DPL must equal CPL else #TS(SS)
10753 If conforming then DPL must be ¾ CPL else #TS(SS)
10754 CS descriptor AR byte must indicate PRESENT else #TS(SS)
10755 Load CS cache with new code segment descriptor and set valid bit
10757 If new selector is not null then perform following checks:
10758 Index must be within its descriptor table limits else
10759 #TS(segment selector)
10760 AR byte must indicate data or readable code else
10761 #TS(segment selector)
10762 If data or non-conforming code then:
10763 DPL must be � CPL else #TS(SS)
10764 DPL must be � RPL else #TS(SS)
10765 AR byte must indicate PRESENT else #TS(SS)
10766 Load cache with new segment descriptor and set valid bit
10769 Table B-3. Hexadecimal Values for the Access Rights Byte
10772 Not present, Present, Descriptor Type
10773 privilege= privilege=
10776 00 20 40 60 80 A0 C0 E0 Illegal
10777 01 21 41 61 81 A1 C1 E1 Available Task State Segment
10778 02 22 42 62 82 A2 C2 E2 Local Descriptor Table Segment
10779 03 23 43 63 83 A3 C3 E3 Busy Task State Segment
10780 04 24 44 64 84 A4 C4 E4 Call Gate
10781 05 25 45 65 85 A5 C5 E5 Task Gate
10782 06 26 46 66 86 A6 C6 E6 Interrupt Gate
10783 07 27 47 67 87 A7 C7 E7 Trap Gate
10784 08 28 48 68 88 A8 C8 E8 Illegal
10785 09 29 49 69 89 A9 C9 E9 Illegal
10786 0A 2A 4A 6A 8A AA CA EA Illegal
10787 0B 2B 4B 6B 8B AB CB EB Illegal
10788 0C 2C 4C 6C 8C AC CC EC Illegal
10789 0D 2D 4D 6D 8D AD CD ED Illegal
10790 0E 2E 4E 6E 8E AE CE EE Illegal
10791 0F 2F 4F 6F 8F AF CF EF Illegal
10792 10 30 50 70 90 B0 D0 F0 Expand-up, read only, ignored Data Segment
10793 11 31 51 71 91 B1 D1 F1 Expand-up, read only, accessed Data Segment
10794 12 32 52 72 92 B2 D2 F2 Expand-up, writable, ignored Data Segment
10795 13 33 53 73 93 B3 D3 F3 Expand-up, writable, accessed Data Segment
10796 14 34 54 74 94 B4 D4 F4 Expand-down, read only, ignored Data Segment
10797 15 35 55 75 95 B5 D5 F5 Expand-down, read only, accessed Data Segment
10798 16 36 56 76 96 B6 D6 F6 Expand-down, writable, ignored Data Segment
10799 17 37 57 77 97 B7 D7 F7 Expand-down, writable, accessed Data Segment
10800 18 38 58 78 98 B8 D8 F8 Non-conform, no read, ignored Code Segment
10801 19 39 59 79 99 B9 D9 F9 Non-conform, no read, accessed Code Segment
10802 1A 3A 5A 7A 9A BA DA FA Non-conform, readable, ignored Code Segment
10803 1B 3B 5B 7B 9B BB DB FB Non-conform, readable, accessed Code Segment
10804 1C 3C 5C 7C 9C BC DC FC Conforming, no read, ignored Code Segment
10805 1D 3D 5D 7D 9D BD DD FD Conforming, no read, accessed Code Segment
10806 1E 3E 5E 7E 9E BE DE FE Conforming, readable, ignored Code Segment
10807 1F 3F 5F 7F 9F BF DF FF Conforming, readable, accessed Code Segment
10810 AAA‘‘ASCII Adjust AL After Addition
10812 Opcode Instruction Clocks Description
10814 37 AAA 3 ASCII adjust AL after addition
10818 Auxiliary carry, carry
10822 Overflow, sign, zero, parity
10826 AAA should be executed only after an ADD instruction which leaves a byte
10827 result in the AL register. The lower nibbles of the operands to the ADD
10828 instruction should be in the range 0 through 9 (BCD digits). In this case,
10829 the AAA instruction will adjust AL to contain the correct decimal digit
10830 result. If the addition produced a decimal carry, the AH register is
10831 incremented, and the carry and auxiliary carry flags are set to 1. If there
10832 was no decimal carry, the carry and auxiliary carry flags are set to 0, and
10833 AH is unchanged. In any case, AL is left with its top nibble set to 0. To
10834 convert AL to an ASCII result, you can follow the AAA instruction with OR
10837 The precise definition of AAA is as follows: if the lower 4 bits of AL are
10838 greater than nine, or if the auxiliary carry flag is 1, then increment AL by
10839 6, AH by 1, and set the carry and auxiliary carry flags. Otherwise, reset
10840 the carry and auxiliary carry flags. In any case, conclude the AAA
10841 operation by setting the upper four bits of AL to zero.
10843 Protected Mode Exceptions
10847 Real Address Mode Exceptions
10851 AAD‘‘ASCII Adjust AX Before Division
10853 Opcode Instruction Clocks Description
10855 D5 0A AAD 14 ASCII adjust AX before division
10863 Overflow, auxiliary carry, carry
10867 AAD is used to prepare two unpacked BCD digits (least significant in AL,
10868 most significant in AH) for a division operation which will yield an
10869 unpacked result. This is accomplished by setting AL to AL + (10 * AH), and
10870 then setting AH to 0. This leaves AX equal to the binary equivalent of the
10871 original unpacked 2-digit number.
10873 Protected Mode Exceptions
10877 Real Address Mode Exceptions
10882 AAM‘‘ASCII Adjust AX After Multiply
10884 Opcode Instruction Clocks Description
10886 D4 0A AAM 16 ASCII adjust AX after multiply
10894 Overflow, auxiliary carry, carry
10898 AAM should be used only after executing a MUL instruction between two
10899 unpacked BCD digits, leaving the result in the AX register. Since the result
10900 is less than one hundred, it is contained entirely in the AL register. AAM
10901 unpacks the AL result by dividing AL by ten, leaving the quotient (most
10902 significant digit) in AH, and the remainder (least significant digit) in
10905 Protected Mode Exceptions
10909 Real Address Mode Exceptions
10914 AAS‘‘ASCII Adjust AL After Subtraction
10916 Opcode Instruction Clocks Description
10918 3F AAS 3 ASCII adjust AL after subtraction
10922 Auxiliary carry, carry
10926 Overflow, sign, zero, parity
10930 AAS should be executed only after a subtraction instruction which left the
10931 byte result in the AL register. The lower nibbles of the operands to the SUB
10932 instruction should have been in the range 0 through 9 (BCD digits). In this
10933 case, the AAS instruction will adjust AL to contain the correct decimal
10934 digit result. If the subtraction produced a decimal carry, the AH register
10935 is decremented, and the carry and auxiliary carry flags are set to 1. If
10936 there was no decimal carry, the carry and auxiliary carry flags are set to
10937 0, and AH is unchanged. In any case, AL is left with its top nibble set to
10938 0. To convert AL to an ASCII result, you can follow the AAS instruction with
10941 The precise definition of AAS is as follows: if the lower four bits of AL
10942 are greater than 9, or if the auxiliary carry flag is 1, then decrement AL
10943 by 6, AH by 1, and set the carry and auxiliary carry flags. Otherwise, reset
10944 the carry and auxiliary carry flags. In any case, conclude the AAS
10945 operation by setting the upper four bits of AL to zero.
10947 Protected Mode Exceptions
10951 Real Address Mode Exceptions
10956 ADC/ADD‘‘Integer Addition
10959 Opcode Instruction Clocks Description
10961 10 /r ADC eb,rb 2,mem=7 Add with carry byte register into EA byte
10962 11 /r ADC ew,rw 2,mem=7 Add with carry word register into EA word
10963 12 /r ADC rb,eb 2,mem=7 Add with carry EA byte into byte register
10964 13 /r ADC rw,ew 2,mem=7 Add with carry EA word into word register
10965 14 db ADC AL,db 3 Add with carry immediate byte into AL
10966 15 dw ADC AX,dw 3 Add with carry immediate word into AX
10967 80 /2 db ADC eb,db 3,mem=7 Add with carry immediate byte into EA byte
10968 81 /2 dw ADC ew,dw 3,mem=7 Add with carry immediate word into EA word
10969 83 /2 db ADC ew,db 3,mem=7 Add with carry immediate byte into EA word
10970 00 /r ADD eb,rb 2,mem=7 Add byte register into EA byte
10971 01 /r ADD ew,rw 2,mem=7 Add word register into EA word
10972 02 /r ADD rb,eb 2,mem=7 Add EA byte into byte register
10973 03 /r ADD rw,ew 2,mem=7 Add EA word into word register
10974 04 db ADD AL,db 3 Add immediate byte into AL
10975 05 dw ADD AX,dw 3 Add immediate word into AX
10976 80 /0 db ADD eb,db 3,mem=7 Add immediate byte into EA byte
10977 81 /0 dw ADD ew,dw 3,mem=7 Add immediate word into EA word
10978 83 /0 db ADD ew,db 3,mem=7 Add immediate byte into EA word
10983 Overflow, sign, zero, auxiliary carry, parity, carry
10991 ADD and ADC perform an integer addition on the two operands. The ADC
10992 instruction also adds in the initial state of the carry flag. The result of
10993 the addition goes to the first operand. ADC is usually executed as part of a
10994 multi-byte or multi-word addition operation.
10996 When a byte immediate value is added to a word operand, the immediate value
10997 is first sign-extended.
10999 Protected Mode Exceptions
11001 #GP(0) if the result is in a non-writable segment. #GP(0) for an illegal
11002 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
11003 an illegal address in the SS segment.
11005 Real Address Mode Exceptions
11007 Interrupt 13 for a word operand at offset 0FFFFH.
11012 Opcode Instruction Clocks Description
11014 20 /r AND eb,rb 2,mem=7 Logical-AND byte register into EA byte
11015 21 /r AND ew,rw 2,mem=7 Logical-AND word register into EA word
11016 22 /r AND rb,eb 2,mem=7 Logical-AND EA byte into byte register
11017 23 /r AND rw,ew 2,mem=7 Logical-AND EA word into word register
11018 24 db AND AL,db 3 Logical-AND immediate byte into AL
11019 25 dw AND AX,dw 3 Logical-AND immediate word into AX
11020 80 /4 db AND eb,db 3,mem=7 Logical-AND immediate byte into EA byte
11021 81 /4 dw AND ew,dw 3,mem=7 Logical-AND immediate word into EA word
11025 Overflow=0, sign, zero, parity, carry=0
11033 Each bit of the result is a 1 if both corresponding bits of the operands
11034 were 1; it is 0 otherwise.
11036 Protected Mode Exceptions
11038 #GP(0) if the result is in a non-writable segment. #GP(0) for an illegal
11039 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
11040 an illegal address in the SS segment.
11042 Real Address Mode Exceptions
11044 Interrupt 13 for a word operand at offset 0FFFFH.
11047 ARPL‘‘Adjust RPL Field of Selector
11049 Opcode Instruction Clocks Description
11051 63 /r ARPL ew,rw 10,mem=11 Adjust RPL of EA word not less than
11064 The ARPL instruction has two operands. The first operand is a 16-bit memory
11065 variable or word register that contains the value of a selector. The second
11066 operand is a word register. If the RPL field (bottom two bits) of the first
11067 operand is less than the RPL field of the second operand, then the zero
11068 flag is set to 1 and the RPL field of the first operand is increased to
11069 match the second RPL. Otherwise, the zero flag is set to 0 and no change is
11070 made to the first operand.
11072 ARPL appears in operating systems software, not in applications programs.
11073 It is used to guarantee that a selector parameter to a subroutine does not
11074 request more privilege than the caller was entitled to. The second operand
11075 used by ARPL would normally be a register that contains the CS selector
11076 value of the caller.
11078 Protected Mode Exceptions
11080 #GP(0) if the result is in a non-writable segment. #GP(0) for an illegal
11081 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
11082 an illegal address in the SS segment.
11084 Real Address Mode Exceptions
11086 Interrupt 6. ARPL is not recognized in Real Address mode.
11089 BOUND‘‘Check Array Index Against Bounds
11091 Opcode Instruction Clocks Description
11093 62 /r BOUND rw,md noj=13 INT 5 if rw not within bounds
11105 BOUND is used to ensure that a signed array index is within the limits
11106 defined by a two-word block of memory. The first operand (a register) must
11107 be greater than or equal to the first word in memory, and less than or equal
11108 to the second word in memory. If the register is not within the bounds, an
11109 INTERRUPT 5 occurs.
11111 The two-word block might typically be found just before the array itself
11112 and therefore would be accessible at a constant offset of -4 from the array,
11113 simplifying the addressing.
11115 Protected Mode Exceptions
11117 INTERRUPT 5 if the bounds test fails, as described above. #GP(0) for an
11118 illegal memory operand effective address in the CS, DS, or ES segments;
11119 #SS(0) for an illegal address in the SS segment.
11121 The second operand must be a memory operand, not a register. If the BOUND
11122 instruction is executed with a ModRM byte representing a register second
11123 operand, then fault #UD will occur.
11125 Real Address Mode Exceptions
11127 INTERRUPT 5 if the bounds test fails, as described above. Interrupt 13 for
11128 a second operand at offset 0FFFDH or higher. Interrupt 6 if the second
11129 operand is a register, as described in the paragraph above.
11132 CALL‘‘Call Procedure
11135 Opcode Instruction Clocks
11136 Add one clock for each byte in the next instruction executed. Description
11138 E8 cw CALL cw 7 Call near, offset relative to
11140 FF /2 CALL ew 7,mem=11 Call near, offset absolute at EA word
11141 9A cd CALL cd 13,pm=26 Call inter-segment, immediate
11143 9A cd CALL cd 41 Call gate, same privilege
11144 9A cd CALL cd 82 Call gate, more privilege,
11146 9A cd CALL cd 86+4X Call gate, more privilege,
11148 9A cd CALL cd 177 Call via Task State Segment
11149 9A cd CALL cd 182 Call via task gate
11150 FF /3 CALL ed 16,mem=29 Call inter-segment, address at
11152 FF /3 CALL ed 44 Call gate, same privilege
11153 FF /3 CALL ed 83 Call gate, more privilege,
11155 FF /3 CALL ed 90+4X Call gate, more privilege,
11157 FF /3 CALL ed 180 Call via Task State Segment
11158 FF /3 CALL ed 185 Call via task gate
11163 None, except when a task switch occurs
11171 The CALL instruction causes the procedure named in the operand to be
11172 executed. When the procedure is complete (a return instruction is executed
11173 within the procedure), execution continues at the instruction that follows
11174 the CALL instruction.
11176 The CALL cw form of the instruction adds modulo 65536 (the 2-byte operand)
11177 to the offset of the instruction following the CALL and sets IP to the
11178 resulting offset. The 2-byte offset of the instruction that follows the CALL
11179 is pushed onto the stack. It will be popped by a near RET instruction
11180 within the procedure. The CS register is not changed by this form.
11182 The CALL ew form of the instruction is the same as CALL cw except that the
11183 operand specifies a memory location from which the absolute 2-byte offset
11184 for the procedure is fetched.
11186 The CALL cd form of the instruction uses the 4-byte operand as a pointer to
11187 the procedure called. The CALL ed form fetches the long pointer from the
11188 memory location specified. Both long pointer forms consult the AR byte in
11189 the descriptor indexed by the selector part of the long pointer. The AR byte
11190 can indicate one of the following descriptor types:
11192 1. Code Segment‘‘The access rights are checked, the return pointer is
11193 pushed onto the stack, and the procedure is jumped to.
11195 2. Call Gate‘‘The offset part of the pointer is ignored. Instead, the
11196 entire address of the procedure is taken from the call gate descriptor
11197 entry. If the routine being entered is more privileged, then a new
11198 stack (both SS and SP) is loaded from the task state segment for the
11199 new privilege level, and parameters determined by the wordcount field
11200 of the call gate are copied from the old stack to the new stack.
11202 3. Task Gate‘‘The current task's context is saved in its Task State
11203 Segment (TSS), and the TSS named in the task-gate is used to load the
11204 new context. The selector for the outgoing task (from TR) is stored
11205 into the new TSS's link field, and the new task's Nested Task flag is
11206 set. The outgoing task is left marked busy, the new TSS is marked
11207 busy, and execution resumes at the point at which the new task was
11210 4. Task State Segment‘‘The current task is suspended and the new task
11211 initiated as in 3 above except that there is no intervening gate.
11213 For long calls involving no task switch, the return link is the pointer of
11214 the instruction that follows the CALL, i.e., the caller's CS and updated IP.
11215 Task switches invoked by CALLs are linked by storing the outgoing task's TSS
11216 selector in the incoming TSS's link field and setting the Nested Task flag
11217 in the new task. Nested tasks must be terminated by an IRET. IRET releases
11218 the nested task and follows the back link to the calling task if the NT flag
11221 A precise list of the protection checks made and the actions taken is given
11222 by the following list:
11225 If indirect then check access of EA doubleword #GP(0) if limit violation
11226 New CS selector must not be null else #GP(0)
11227 Check that new CS selector index is within its descriptor table limits;
11228 else #GP (new CS selector)
11229 Examine AR byte of selected descriptor for various legal values:
11231 CALL CONFORMING CODE SEGMENT:
11232 DPL must be ¾ CPL else #GP (code segment selector)
11233 Segment must be PRESENT else #NP (code segment selector)
11234 Stack must be big enough for return address else #SS(0)
11235 IP must be in code segment limit else #GP(0)
11236 Load code segment descriptor into CS cache
11237 Load CS with new code segment selector
11238 Load IP with new offset
11240 CALL NONCONFORMING CODE SEGMENT:
11241 RPL must be ¾ CPL else #GP (code segment selector)
11242 DPL must be = CPL else #GP (code segment selector)
11243 Segment must be PRESENT else #NP (code segment selector)
11244 Stack must be big enough for return address else #SS(0)
11245 IP must be in code segment limit else #GP(0)
11246 Load code segment descriptor into CS cache
11247 Load CS with new code segment selector
11248 Set RPL of CS to CPL
11249 Load IP with new offset
11252 Call gate DPL must be � CPL else #GP (call gate selector)
11253 Call gate DPL must be � RPL else #GP (call gate selector)
11254 Call gate must be PRESENT else #NP (call gate selector)
11255 Examine code segment selector in call gate descriptor:
11256 Selector must not be null else #GP(0)
11257 Selector must be within its descriptor table limits else #GP (code
11259 AR byte of selected descriptor must indicate code segment else #GP
11260 (code segment selector)
11261 DPL of selected descriptor must be ¾ CPL else #GP(code segment
11263 If non-conforming code segment and DPL < CPL then
11265 CALL GATE TO MORE PRIVILEGE:
11266 Get new SS selector for new privilege level from TSS
11267 Check selector and descriptor for new SS:
11268 Selector must not be null else #TS(0)
11269 Selector index must be within its descriptor table limits else #TS
11271 Selector's RPL must equal DPL of code segment else #TS (SS selector)
11272 Stack segment DPL must equal DPL of code segment else #TS
11274 Descriptor must indicate writable data segment else #TS (SS selector)
11275 Segment PRESENT else #SS (SS selector)
11276 New stack must have room for parameters plus 8 bytes else #SS(0)
11277 IP must be in code segment limit else #GP(0)
11278 Load new SS:SP value from TSS
11279 Load new CS:IP value from gate
11282 Push long pointer of old stack onto new stack
11283 Get word count from call gate, mask to 5 bits
11284 Copy parameters from old stack onto new stack
11285 Push return address onto new stack
11286 Set CPL to stack segment DPL
11287 Set RPL of CS to CPL
11289 CALL GATE TO SAME PRIVILEGE:
11290 Stack must have room for 4-byte return address else #SS(0)
11291 IP must be in code segment limit else #GP(0)
11292 Load CS:IP from gate
11293 Push return address onto stack
11294 Load code segment descriptor into CS-cache
11295 Set RPL of CS to CPL
11298 Task gate DPL must be � CPL else #GP (gate selector)
11299 Task gate DPL must be � RPL else #GP (gate selector)
11300 Task Gate must be PRESENT else #NP (gate selector)
11301 Examine selector to TSS, given in Task Gate descriptor:
11302 Must specify global in the local/global bit else #GP
11304 Index must be within GDT limits else #GP (TSS selector)
11305 TSS descriptor AR byte must specify available TSS (bottom bits
11306 00001) else #GP (TSS selector)
11307 Task State Segment must be PRESENT else #NP (TSS selector)
11308 SWITCH_TASKS with nesting to TSS
11309 IP must be in code segment limit else #GP(0)
11311 TASK STATE SEGMENT:
11312 TSS DPL must be � CPL else #GP (TSS selector)
11313 TSS DPL must be � RPL else #GP (TSS selector)
11314 TSS descriptor AR byte must specify available TSS else #GP
11316 Task State Segment must be PRESENT else #NP (TSS selector)
11317 SWITCH_TASKS with nesting to TSS
11318 IP must be in code segment limit else #GP(0)
11320 ELSE #GP (code segment selector)
11322 Protected Mode Exceptions
11324 FAR calls: #GP, #NP, #SS, and #TS, as indicated in the list above.
11326 NEAR direct calls: #GP(0) if procedure location is beyond the code segment
11329 NEAR indirect CALL: #GP(0) for an illegal memory operand effective address
11330 in the CS, DS, or ES segments; #SS(0) for an illegal address in the SS
11331 segment. #GP if the indirect offset obtained is beyond the code segment
11334 Real Address Mode Exceptions
11336 Interrupt 13 for a word operand at offset 0FFFFH.
11339 CBW‘‘Convert Byte into Word
11341 Opcode Instruction Clocks Description
11343 98 CBW 2 Convert byte into word (AH = top bit of AL)
11355 CBW converts the signed byte in AL to a signed word in AX. It does so by
11356 extending the top bit of AL into all of the bits of AH.
11358 Protected Mode Exceptions
11362 Real Address Mode Exceptions
11367 CLC‘‘Clear Carry Flag
11369 Opcode Instruction Clocks Description
11371 F8 CLC 2 Clear carry flag
11383 CLC sets the carry flag to zero. No other flags or registers are affected.
11385 Protected Mode Exceptions
11389 Real Address Mode Exceptions
11394 CLD‘‘Clear Direction Flag
11396 Opcode Instruction Clocks Description
11398 FC CLD 2 Clear direction flag, SI and DI
11411 CLD clears the direction flag. No other flags or registers are affected.
11412 After CLD is executed, string operations will increment the index registers
11413 (SI and/or DI) that they use.
11415 Protected Mode Exceptions
11419 Real Address Mode Exceptions
11424 CLI‘‘Clear Interrupt Flag
11426 Opcode Instruction Clocks Description
11428 FA CLI 3 Clear interrupt flag; interrupts disabled
11440 CLI clears the interrupt enable flag if the current privilege level is at
11441 least as privileged as IOPL. No other flags are affected. External
11442 interrupts will not be recognized at the end of the CLI instruction or
11443 thereafter until the interrupt flag is set.
11445 Protected Mode Exceptions
11447 #GP(0) if the current privilege level is bigger (has less privilege) than
11448 the IOPL in the flags register. IOPL specifies the least privileged level at
11449 which I/O may be performed.
11451 Real Address Mode Exceptions
11456 CLTS‘‘Clear Task Switched Flag
11458 Opcode Instruction Clocks Description
11460 0F 06 CLTS 2 Clear task switched flag
11472 CLTS clears the task switched flag in the Machine Status Word. This flag is
11473 set by the 80286 every time a task switch occurs. The TS flag is used to
11474 manage processor extensions as follows: every execution of a WAIT or an ESC
11475 instruction will be trapped if the MP flag of MSW is set and the task
11476 switched flag is set. Thus, if a processor extension is present and a task
11477 switch has been made since the last ESC instruction was begun, the processor
11478 extension's context must be saved before a new instruction can be issued.
11479 The fault routine will save the context and reset the task switched flag or
11480 place the task requesting the processor extension into a queue until the
11481 current processor extension instruction is completed.
11483 CLTS appears in operating systems software, not in applications programs.
11484 It is a privileged instruction that can only be executed at level 0.
11486 Protected Mode Exceptions
11488 #GP(0) if CLTS is executed with a current privilege level other than 0.
11490 Real Address Mode Exceptions
11492 None (valid in REAL ADDRESS MODE to allow power-up initialization for
11496 CMC‘‘Complement Carry Flag
11498 Opcode Instruction Clocks Description
11500 F5 CMC 2 Complement carry flag
11512 CMC reverses the setting of the carry flag. No other flags are affected.
11514 Protected Mode Exceptions
11518 Real Address Mode Exceptions
11523 CMP‘‘Compare Two Operands
11525 Opcode Instruction Clocks Description
11527 3C db CMP AL,db 3 Compare immediate byte from AL
11528 3D dw CMP AX,dw 3 Compare immediate word from AX
11529 80 /7 db CMP eb,db 3,mem=6 Compare immediate byte from EA byte
11530 38 /r CMP eb,rb 2,mem=7 Compare byte register from EA byte
11531 83 /7 db CMP ew,db 3,mem=6 Compare immediate byte from EA word
11532 81 /7 dw CMP ew,dw 3,mem=6 Compare immediate word from EA word
11533 39 /r CMP ew,rw 2,mem=7 Compare word register from EA word
11534 3A /r CMP rb,eb 2,mem=6 Compare EA byte from byte register
11535 3B /r CMP rw,ew 2,mem=6 Compare EA word from word register
11539 Overflow, sign, zero, auxiliary carry, parity, carry
11547 CMP subtracts the second operand from the first operand, but it does not
11548 place the result anywhere. Only the flags are changed by this instruction.
11549 CMP is usually followed by a conditional jump instruction. See the "Jcond"
11550 instructions in this chapter for the list of signed and unsigned flag tests
11551 provided by the 80286.
11553 If a word operand is compared to an immediate byte value, the byte value is
11554 first sign-extended.
11556 Protected Mode Exceptions
11558 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
11559 segments; #SS(0) for an illegal address in the SS segment.
11561 Real Address Mode Exceptions
11563 Interrupt 13 for a word operand at offset 0FFFFH.
11566 CMPS/CMPSB/CMPSW‘‘Compare string operands
11568 Opcode Instruction Clocks Description
11570 A6 CMPS mb,mb 8 Compare bytes ES:[DI] from [SI]
11571 A6 CMPSB 8 Compare bytes ES:[DI] from DS:[SI]
11572 A7 CMPSW 8 Compare words ES:[DI] from DS:[SI]
11576 Overflow, sign, zero, auxiliary carry, parity, carry
11584 CMPS compares the byte or word pointed to by SI with the byte or word
11585 pointed to by DI by performing the subtraction [SI] - [DI]. The result is
11586 not placed anywhere; only the flags reflect the result of the subtraction.
11587 The types of the operands to CMPS determine whether bytes or words are
11588 compared. The segment addressability of the first (SI) operand determines
11589 whether a segment override byte will be produced or whether the default
11590 segment register DS is used. The second (DI) operand must be addressible
11591 from the ES register; no segment override is possible.
11593 After the comparison is made, both SI and DI are automatically advanced. If
11594 the direction flag is 0 (CLD was executed), the registers increment; if the
11595 direction flag is 1 (STD was executed), the registers decrement. The
11596 registers increment or decrement by 1 if a byte was moved; by 2 if a word
11599 CMPS cn be preceded by the REPE or REPNE prefix for block comparison of CX
11600 bytes or words. Refer to the REP instruction for details of this operation.
11602 Protected Mode Exceptions
11604 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
11605 segments; #SS(0) for an illegal address in the SS segment.
11607 Real Address Mode Exceptions
11609 Interrupt 13 for a word operand at offset 0FFFFH.
11612 CWD‘‘Convert Word to Doubleword
11614 Opcode Instruction Clocks Description
11616 99 CWD 2 Convert word to doubleword (DX:AX = AX)
11628 CWD converts the signed word in AX to a signed doubleword in DX:AX. It does
11629 so by extending the top bit of AX into all the bits of DX.
11631 Protected Mode Exceptions
11635 Real Address Mode Exceptions
11640 DAA‘‘Decimal Adjust AL After Addition
11642 Opcode Instruction Clocks Description
11644 27 DAA 3 Decimal adjust AL after addition
11648 Sign, zero, auxiliary carry, parity, carry
11656 DAA should be executed only after an ADD instruction which leaves a
11657 two-BCD-digit byte result in the AL register. The ADD operands should
11658 consist of two packed BCD digits. In this case, the DAA instruction will
11659 adjust AL to contain the correct two-digit packed decimal result.
11661 The precise definition of DAA is as follows:
11663 1. If the lower 4 bits of AL are greater than nine, or if the auxiliary
11664 carry flag is 1, then increment AL by 6, and set the auxiliary carry
11665 flag. Otherwise, reset the auxiliary carry flag.
11667 2. If AL is now greater than 9FH, or if the carry flag is set, then
11668 increment AL by 60H, and set the carry flag. Otherwise, clear the
11671 Protected Mode Exceptions
11675 Real Address Mode Exceptions
11680 DAS‘‘Decimal Adjust AL After Subtraction
11682 Opcode Instruction Clocks Description
11684 2F DAS 3 Decimal adjust AL after subtraction
11688 Sign, zero, auxiliary carry, parity, carry
11696 DAS should be executed only after a subtraction instruction which leaves a
11697 two-BCD-digit byte result in the AL register. The operands should consist of
11698 two packed BCD digits. In this case, the DAS instruction will adjust AL to
11699 contain the correct packed two-digit decimal result.
11701 The precise definition of DAS is as follows:
11703 1. If the lower four bits of AL are greater than 9, or if the auxiliary
11704 carry flag is 1, then decrement AL by 6, and set the auxiliary carry
11705 flag. Otherwise, reset the auxiliary carry flag.
11707 2. If AL is now greater than 9FH, or if the carry flag is set, then
11708 decrement AL by 60H, and set the carry flag. Otherwise, clear the
11711 Protected Mode Exceptions
11715 Real Address Mode Exceptions
11720 DEC‘‘Decrement by 1
11722 Opcode Instruction Clocks Description
11724 FE /1 DEC eb 2,mem=7 Decrement EA byte by 1
11725 FF /1 DEC ew 2,mem=7 Decrement EA word by 1
11726 48+ rw DEC rw 2 Decrement word register by 1
11730 Overflow, sign, zero, auxiliary carry, parity
11738 1 is subtracted from the operand. Note that the carry flag is not changed
11739 by this instruction. If you want the carry flag set, use the SUB instruction
11740 with a second operand of 1.
11742 Protected Mode Exceptions
11744 #GP(0) if the operand is in a non-writable segment. #GP(0) for an illegal
11745 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
11746 an illegal address in the SS segment.
11748 Real Address Mode Exceptions
11750 Interrupt 13 for a word operand at offset 0FFFFH.
11753 DIV‘‘Unsigned Divide
11755 Opcode Instruction Clocks Description
11757 F6 /6 DIV eb 14,mem=17 Unsigned divide AX by EA byte
11758 F7 /6 DIV ew 22,mem=25 Unsigned divide DX:AX by
11767 Overflow, sign, zero, auxiliary carry, parity, carry
11771 DIV performs an unsigned divide. The dividend is implicit; only the divisor
11772 is given as an operand. If the source operand is a BYTE operand, divide AX
11773 by the byte. The quotient is stored in AL, and the remainder is stored in
11774 AH. If the source operand is a WORD operand, divide DX:AX by the word. The
11775 high-order 16 bits of the dividend are kept in DX. The quotient is stored
11776 in AX, and the remainder is stored in DX. Non-integral quotients are
11777 truncated towards 0. The remainder is always less than the dividend.
11779 Protected Mode Exceptions
11781 Interrupt 0 if the quotient is too big to fit in the designated register
11782 (AL or AX), or if the divisor is zero. #GP(0) for an illegal memory operand
11783 effective address in the CS, DS, or ES segments; #SS(0) for an illegal
11784 address in the SS segment.
11786 Real Address Mode Exceptions
11788 Interrupt 0 if the quotient is too big to fit in the designated register
11789 (AL or AX), or if the divisor is zero. Interrupt 13 for a word operand at
11793 ENTER‘‘Make Stack Frame for Procedure Parameters
11795 Opcode Instruction Clocks Description
11797 C8 dw 00 ENTER dw,0 11 Make stack frame for procedure parameters
11798 C8 dw 01 ENTER dw,1 15 Make stack frame for procedure parameters
11799 C8 dw db ENTER dw,db 12+4db Make stack frame for procedure parameters
11811 ENTER is used to create the stack frame required by most block-structured
11812 high-level languages. The first operand specifies how many bytes of dynamic
11813 storage are to be allocated on the stack for the routine being entered. The
11814 second operand gives the lexical nesting level of the routine within the
11815 high-level-language source code. It determines how many stack frame
11816 pointers are copied into the new stack frame from the preceding frame. BP is
11817 used as the current stack frame pointer.
11819 If the second operand is 0, ENTER pushes BP, sets BP to SP, and subtracts
11820 the first operand from SP.
11822 For example, a procedure with 12 bytes of local variables would have an
11823 ENTER 12,0 instruction at its entry point and a LEAVE instruction before
11824 every RET. The 12 local bytes would be addressed as negative offsets from
11825 [BP]. See also section 4.2.
11827 The formal definition of the ENTER instruction for all cases is given by
11828 the following listing. LEVEL denotes the value of the second operand.
11830 LEVEL:=LEVEL MOD 32
11832 Set a temporary value FRAME_PTR := SP
11834 Repeat (LEVEL-1) times:
11836 Push the word pointed to by BP
11841 SP := SP - first operand
11843 Protected Mode Exceptions
11845 #SS(0) if SP were to go outside of the stack limit within any part of the
11846 instruction execution.
11848 Real Address Mode Exceptions
11855 Opcode Instruction Clocks Description
11869 Successful execution of HLT causes the 80286 to cease executing
11870 instructions and to enter a HALT state. Execution resumes only upon receipt
11871 of an enabled interrupt or a reset. If an interrupt is used to resume
11872 program execution after HLT, the saved CS:IP value will point to the
11873 instruction that follows HLT.
11875 Protected Mode Exceptions
11877 HLT is a privileged instruction. #GP(0) if the current privilege level is
11880 Real Address Mode Exceptions
11885 IDIV‘‘Signed Divide
11887 Opcode Instruction Clocks Description
11889 F6 /7 IDIV eb 17,mem=20 Signed divide AX by EA byte
11891 F7 /7 IDIV ew 25,mem=28 Signed divide DX:AX by
11892 EA word (AX=Quo,DX=Rem)
11900 Overflow, sign, zero, auxiliary carry, parity, carry
11904 IDIV performs a signed divide. The dividend is implicit; only the divisor
11905 is given as an operand. If the source operand is a BYTE operand, divide AX
11906 by the byte. The quotient is stored in AL, and the remainder is stored in
11907 AH. If the source operand is a WORD operand, divide DX:AX by the word. The
11908 high-order 16 bits of the dividend are in DX. The quotient is stored in AX,
11909 and the remainder is stored in DX. Non-integral quotients are truncated
11910 towards 0. The remainder has the same sign as the dividend and always has
11911 less magnitude than the dividend.
11913 Protected Mode Exceptions
11915 Interrupt 0 if the quotient is too big to fit in the designated register
11916 (AL or AX), or if the divisor is 0. #GP(0) for an illegal memory operand
11917 effective address in the CS, DS, or ES segments; #SS(0) for an illegal
11918 address in the SS segment.
11920 Real Address Mode Exceptions
11922 Interrupt 0 if the quotient is too big to fit in the designated register
11923 (AL or AX), or if the divisor is 0. Interrupt 13 for a word operand at
11927 IMUL‘‘Signed Multiply
11929 Opcode Instruction Clocks Description
11931 F6 /5 IMUL eb 13,mem=16 Signed multiply (AX = AL * EA byte)
11932 F7 /5 IMUL ew 21,mem=24 Signed multiply (DXAX = AX * EA word)
11933 6B /r db IMUL rw,db 21,mem=24 Signed multiply imm. byte
11935 69 /r dw IMUL rw,ew,dw 21,mem=24 Signed multiply
11936 (rw = EA word * imm. word)
11937 6B /r db IMUL rw,ew,db 21,mem=24 Signed multiply
11938 (rw = EA word * imm. byte)
11946 Sign, zero, auxiliary carry, parity
11950 IMUL performs signed multiplication. If IMUL has a single byte source
11951 operand, then the source is multiplied by AL and the 16-bit signed result is
11952 left in AX. Carry and overflow are set to 0 if AH is a sign extension of AL;
11953 they are set to 1 otherwise.
11955 If IMUL has a single word source operand, then the source operand is
11956 multiplied by AX and the 32-bit signed result is left in DX:AX. DX contains
11957 the high-order 16 bits of the product. Carry and overflow are set to 0 if DX
11958 is a sign extension of AX; they are set to 1 otherwise.
11960 If IMUL has three operands, then the second operand (an effective address
11961 word) is multiplied by the third operand (an immediate word), and the 16
11962 bits of the result are placed in the first operand (a word register). Carry
11963 and overflow are set to 0 if the result fits in a signed word (between
11964 -32768 and +32767, inclusive); they are set to 1 otherwise.
11966 The low 16 bits of the product of a 16-bit signed multiply are the same as
11967 those of an unsigned multiply. The three operand IMUL instruction can be
11968 used for unsigned operands as well.
11970 Protected Mode Exceptions
11972 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
11973 segments; #SS(0) for an illegal address in the SS segment.
11975 Real Address Mode Exceptions
11977 Interrupt 13 for a word operand at offset 0FFFFH.
11980 IN‘‘Input from Port
11982 Opcode Instruction Clocks Description
11984 E4 db IN AL,db 5 Input byte from immediate portinto AL
11985 EC IN AL,DX 5 Input byte from port DX into AL
11986 E5 db IN AX,db 5 Input word from immediate portinto AX
11987 ED IN AX,DX 5 Input word from port DX into AX
11999 IN transfers a data byte or data word from the port numbered by the second
12000 operand into the register (AL or AX) given as the first operand. You can
12001 access any port from 0 to 65535 by placing the port number in the DX
12002 register then using an IN instruction with DX as the second parameter.
12003 These I/O instructions can be shortened by using an 8-bit port I/O in the
12004 instruction. The upper 8 bits of the port address will be zero when an 8-bit
12007 Intel has reserved I/O port addresses 00F8H through 00FFH; they should not
12010 Protected Mode Exceptions
12012 #GP(0) if the current privilege level is bigger (has less privilege) than
12013 IOPL, which is the privilege level found in the flags register.
12015 Real Address Mode Exceptions
12020 INC‘‘Increment by 1
12022 Opcode Instruction Clocks Description
12024 FE /0 INC eb 2,mem=7 Increment EA byte by 1
12025 FF /0 INC ew 2,mem=7 Increment EA word by 1
12026 40+rw INC rw 2 Increment word register by 1
12030 Overflow, sign, zero, auxiliary carry, parity
12038 1 is added to the operand. Note that the carry flag is not changed by this
12039 instruction. If you want the carry flag set, use the ADD instruction with a
12040 second operand of 1.
12042 Protected Mode Exceptions
12044 #GP(0) if the operand is in a non-writable segment. #GP(0) for an illegal
12045 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
12046 an illegal address in the SS segment.
12048 Real Address Mode Exceptions
12050 Interrupt 13 for a word operand at offset 0FFFFH.
12053 INS/INSB/INSW‘‘Input from Port to String
12055 Opcode Instruction Clocks Description
12057 6C INS eb,DX 5 Input byte from port DX into ES:[DI]
12058 6D INS ew,DX 5 Input word from port DX into ES:[DI]
12059 6C INSB 5 Input byte from port DX into ES:[DI]
12060 6D INSW 5 Input word from port DX into ES:[DI]
12072 INS transfers data from the input port numbered by the DX register to the
12073 memory byte or word at ES:DI. The memory operand must be addressable from
12074 the ES register; no segment override ispossible.
12076 INS does not allow the specification of the port number as an immediate
12077 value. The port must be addressed through the DX register.
12079 After the transfer is made, DI is automatically advanced. If the direction
12080 flag is 0 (CLD was executed), DI increments; if the direction flag is 1 (STD
12081 was executed), DI decrements. DI increments or decrements by 1 if a byte was
12082 moved; by 2 if a word was moved.
12084 INS can be preceded by the REP prefix for block input of CX bytes or words.
12085 Refer to the REP instruction for details of this operation.
12087 Intel has reserved I/O port addresses 00F8H through 00FFH; they should not
12090 Not all input port devices can handle the rate at which this instruction
12091 transfers input data to memory.
12093 Protected Mode Exceptions
12095 #GP(0) if CPL > IOPL. #GP(0) if the destination is in a non-writable
12096 segment. #GP(0) for an illegal memory operand effective address in the CS,
12097 DS, or ES segments; #SS(0) for an illegal address in the SS segment.
12099 Real Address Mode Exceptions
12101 Interrupt 13 for a word operand at offset 0FFFFH.
12104 INT/INTO‘‘Call to Interrupt Procedure
12106 Opcode Instruction Clocks
12107 Add one clock for each byte of the next instruction executed. Description
12110 (real mode) Interrupt 3 (trap to debugger)
12111 CC INT 3 40 Interrupt 3, protected mode, same privilege
12112 CC INT 3 78 Interrupt 3, protected mode, more privilege
12113 CC INT 3 167 Interrupt 3, protected mode, via task gate
12115 (real mode) Interrupt numbered by immediate byte
12116 CD db INT db 40 Interrupt, protected mode, same privilege
12117 CD db INT db 78 Interrupt, protected mode, more privilege
12118 CD db INT db 167 Interrupt, protected mode, via task gate
12120 (real mode) Interrupt 4 if overflow flag is 1
12125 All if a task switch takes place; Trap Flag reset if no task switch takes
12126 place. Interrupt Flag is always reset in Real Mode, and reset in Protected
12127 Mode when INT references an interrupt gate.
12135 The INT instruction generates via software a call to an interrupt
12136 procedure. The immediate operand, from 0 to 255, gives the index number into
12137 the Interrupt Descriptor Table of the interrupt routine to be called. In
12138 protected mode, the IDT consists of 8-byte descriptors; the descriptor for
12139 the interrupt invoked must indicate an interrupt gate, a trap gate, or a
12140 task gate. In real address mode, the IDT is an array of 4-byte long pointers
12141 at the fixed location 00000H.
12143 The INTO instruction is identical to the INT instruction except that the
12144 interrupt number is implicitly 4, and the interrupt is made only if the
12145 overflow flag of the 80286 is on. The clock counts for the four forms of
12146 INT db are valid for INTO, with the number of clocks increased by 1 for the
12147 overflow flag test.
12149 The first 32 interrupts are reserved by Intel for systems use. Some of
12150 these interrupts are exception handlers for internally-generated faults.
12151 Most of these exception handlers should not be invoked with the INT
12154 Generally, interrupts behave like far CALLs except that the flags register
12155 is pushed onto the stack before the return address. Interrupt procedures
12156 return via the IRET instruction, which pops the flags from the stack.
12158 In Real Address mode, INT pushes the flags, CS and the return IP onto the
12159 stack in that order, then resets the Trap Flag, then jumps to the long
12160 pointer indexed by the interrupt number, in the interrupt vector table.
12162 In Protected mode, INT also resets the Trap Flag. In Protected mode, the
12163 precise semantics of the INT instruction are given by the following:
12166 Interrupt vector must be within IDT table limits else #GP (vector number *
12168 Descriptor AR byte must indicate interrupt gate, trap gate, or task gate
12169 else #GP (vector number * 8+2+EXT)
12170 If INT instruction then gate descriptor DPL must be � CPL else #GP (vector
12172 Gate must be PRESENT else #NP (vector number * 8+2+EXT)
12173 If TRAP GATE or INTERRUPT GATE:
12174 Examine CS selector and descriptor given in the gate descriptor:
12175 Selector must be non-null else #GP (EXT)
12176 Selector must be within its descriptor table limits else
12178 Descriptor AR byte must indicate code segment else
12179 #GP (selector + EXT)
12180 Segment must be PRESENT else #NP (selector+EXT)
12181 If code segment is non-conforming and DPL < CPL then
12182 INTERRUPT TO INNER PRIVILEGE:
12183 Check selector and descriptor for new stack in current Task State
12185 Selector must be non-null else #TS(EXT)
12186 Selector index must be within its descriptor table limits else
12187 #TS (SS selector+EXT)
12188 Selector's RPL must equal DPL of code segment else
12189 #TS (SS selector+EXT)
12190 Stack segment DPL must equal DPL of code segment else #TS (SS
12192 Descriptor must indicate writable data segment else #TS (SS
12194 Segment must be PRESENT else #SS (SS selector+EXT)
12195 New stack must have room for 10 bytes else #SS(0)
12196 IP must be in CS limit else #GP(0)
12197 Load new SS and SP value from TSS
12198 Load new CS and IP value from gate
12201 Push long pointer to old stack onto new stack
12202 Push return address onto new stack
12203 Set CPL to new code segment DPL
12204 Set RPL of CS to CPL
12205 If INTERRUPT GATE then set the Interrupts Enabled Flag to 0 (disabled)
12206 Set the Trap Flag to 0
12207 Set the Nested Task Flag to 0
12208 If code segment is conforming or code segment DPL = CPL then
12209 INTERRUPT TO SAME PRIVILEGE LEVEL:
12210 Current stack limits must allow pushing 6 bytes else #SS(0)
12211 If interrupt was caused by fault with error code then
12212 Stack limits must allow push of two more bytes else #SS(0)
12213 IP must be in CS limit else #GP(0)
12214 Push flags onto stack
12215 Push current CS selector onto stack
12216 Push return offset onto stack
12217 Load CS:IP from gate
12219 Set the RPL field of CS to CPL
12220 Push error code (if any) onto stack
12221 If INTERRUPT GATE then set the Interrupts Enabled Flag to 0 (disabled)
12222 Set the Trap Flag to 0
12223 Set the Nested Task Flag to 0
12225 Else #GP (CS selector + EXT)
12228 Examine selector to TSS, given in Task Gate descriptor:
12229 Must specify global in the local/global bit else #GP (TSS selector)
12230 Index must be within GDT limits else #GP (TSS selector)
12231 AR byte must specify available TSS (bottom bits 00001) else #GP (TSS
12233 Task State Segment must be PRESENT else #NP (TSS selector)
12234 SWITCH_TASKS with nesting to TSS
12235 If interrupt was caused by fault with error code then
12236 Stack limits must allow push of two more bytes else #SS(0)
12237 Push error code onto stack
12238 IP must be in CS limit else #GP(0)
12240 EXT is 1 if an external event (i.e., a single step, an external interrupt,
12241 an MF exception, or an MP exception) caused the interrupt; 0 if not (i.e.,
12242 an INT instruction or other exceptions).
12244 Protected Mode Exceptions
12246 #GP, #NP, #SS, and #TS, as indicated in the list above.
12248 Real Address Mode Exceptions
12250 None; the 80286 will shut down if the SP = 1, 3, or 5 before executing the
12251 INT or INTO instruction‘‘due to lack of stack space.
12254 IRET‘‘Interrupt Return
12256 Opcode Instruction Clocks
12257 Add one clock for each byte in the next instruction executed. Description
12259 CF IRET 17,pm=31 Interrupt return (far return and pop flags)
12260 CF IRET 55 Interrupt return, lesser privilege
12261 CF IRET 169 Interrupt return, different task (NT=1)
12266 Entire flags register popped from stack
12274 In real address mode, IRET pops IP, CS, and FLAGS from the stack in that
12275 order, and resumes the interrupted routine.
12277 In protected mode, the action of IRET depends on the setting of the Nested
12278 Task Flag (NT) bit in the flag register. When popping the new flag image
12279 from the stack, note that the IOPL bits in the flag register are changed
12282 If NT=0, IRET returns from an interrupt procedure without a task switch.
12283 The code returned to must be equally or less privileged than the interrupt
12284 routine as indicated by the RPL bits of the CS selector popped from the
12285 stack. If the destination code is of less privilege, IRET then also pops SP
12286 and SS from the stack.
12288 If NT=1, IRET reverses the operation of a CALL or INT that caused a task
12289 switch. The task executing IRET has its updated state saved in its Task
12290 State Segment. This means that if the task is re-entered, the code that
12291 follows IRET will be executed.
12293 The exact checks and actions performed by IRET in protected mode are given
12294 on the following page.
12297 If Nested Task Flag=1 then
12298 RETURN FROM NESTED TASK:
12299 Examine Back Link Selector in TSS addressed by the current Task
12301 Must specify global in the local/global bit else
12302 #TS (new TSS selector)
12303 Index must be within GDT limits else #TS (new TSS selector)
12304 AR byte must specify TSS else #TS (new TSS selector)
12305 New TSS must be busy else #TS (new TSS selector)
12306 Task State Segment must be PRESENT else #NP (new TSS selector)
12307 SWITCH_TASKS without nesting to TSS specified by back link selector
12308 Mark the task just abandoned as NOT BUSY
12309 IP must be in code segment limit else #GP(0)
12310 If Nested Task Flag=0 then
12311 INTERRUPT RETURN ON STACK:
12312 Second word on stack must be within stack limits else #SS(0)
12313 Return CS selector RPL must be � CPL else #GP (Return selector)
12314 If return selector RPL = CPL then
12315 INTERRUPT RETURN TO SAME LEVEL:
12316 Top 6 bytes on stack must be within limits else #SS(0)
12317 Return CS selector (at SP+2) must be non-null else #GP(0)
12318 Selector index must be within its descriptor table limits else
12319 #GP (Return selector)
12320 AR byte must indicate code segment else #GP (Return selector)
12321 If non-conforming then code segment DPL must = CPL else
12322 #GP (Return selector)
12323 If conforming then code segment DPL must be ¾ CPL else
12324 #GP (Return selector)
12325 Segment must be PRESENT else #NP (Return selector)
12326 IP must be in code segment limit else #GP(0)
12327 Load CS:IP from stack
12328 Load CS-cache with new code segment descriptor
12329 Load flags with third word on stack
12332 INTERRUPT RETURN TO OUTER PRIVILEGE LEVEL:
12333 Top 10 bytes on stack must be within limits else #SS(0)
12334 Examine return CS selector (at SP+2) and associated descriptor:
12335 Selector must be non-null else #GP(0)
12336 Selector index must be within its descriptor table limits else
12337 #GP (Return selector)
12338 AR byte must indicate code segment else #GP (Return selector)
12339 If non-conforming then code segment DPL must = CS selector RPL else
12340 #GP (Return selector)
12341 If conforming then code segment DPL must be > CPL else #GP (Return
12343 Segment must be PRESENT else #NP (Return selector)
12344 Examine return SS selector (at SP+8) and associated descriptor:
12345 Selector must be non-null else #GP(0)
12346 Selector index must be within its descriptor table limits else
12348 Selector RPL must equal the RPL of the return CS selector else
12350 AR byte must indicate a writable data segment else
12352 Stack segment DPL must equal the RPL of the return CS selector else
12354 SS must be PRESENT else #SS (SS selector)
12355 IP must be in code segment limit else #GP(0)
12356 Load CS:IP from stack
12357 Load flags with values at (SP+4)
12358 Load SS:SP from stack
12359 Set CPL to the RPL of the return CS selector
12360 Load the CS-cache with the CS descriptor
12361 Load the SS-cache with the SS descriptor
12362 For each of ES and DS:
12363 If the current register setting is not valid for the outer level,
12364 then zero the register and clear the valid flag
12365 To be valid, the register setting must satisfy the following
12367 Selector index must be within descriptor table limits
12368 AR byte must indicate data or readable code segment
12369 If segment is data or non-conforming code, then:
12370 DPL must be � CPL, or
12374 Protected Mode Exceptions
12376 #GP, #NP, or #SS, as indicated in the above listing.
12378 Real Address Mode Exceptions
12380 Interrupt 13 if the stack is popped when it has offset 0FFFFH.
12383 Jcond‘‘Jump Short If Condition Met
12386 Opcode Instruction Clocks
12387 When a jump is taken, add one clock for every byte of the next instruction
12388 executed. Description
12389 77 cb JA cb 7,noj=3 Jump short if above (CF=0 and ZF=0)
12390 73 cb JAE cb 7,noj=3 Jump short if above or equal (CF=0)
12391 72 cb JB cb 7,noj=3 Jump short if below (CF=1)
12392 76 cb JBE cb 7,noj=3 Jump short if below or equal (CF=1 or ZF=1)
12393 72 cb JC cb 7,noj=3 Jump short if carry (CF=1)
12394 E3 cb JCXZ cb 8,noj=4 Jump short if CX register is zero
12395 74 cb JE cb 7,noj=3 Jump short if equal (ZF=1)
12396 7F cb JG cb 7,noj=3 Jump short if greater (ZF=0 and SF=OF)
12397 7D cb JGE cb 7,noj=3 Jump short if greater or equal (SF=OF)
12398 7C cb JL cb 7,noj=3 Jump short if less (SF/=OF)
12399 7E cb JLE cb 7,noj=3 Jump short if less or equal (ZF=1 or SF/=OF)
12400 76 cb JNA cb 7,noj=3 Jump short if not above (CF=1 or ZF=1)
12401 72 cb JNAE cb 7,noj=3 Jump short if not above/equal (CF=1)
12402 73 cb JNB cb 7,noj=3 Jump short if not below (CF=0)
12403 77 cb JNBE cb 7,noj=3 Jump short if not below/equal
12405 73 cb JNC cb 7,noj=3 Jump short if not carry (CF=0)
12406 75 cb JNE cb 7,noj=3 Jump short if not equal (ZF=0)
12407 7E cb JNG cb 7,noj=3 Jump short if not greater (ZF=1 or SF/=OF)
12408 7C cb JNGE cb 7,noj=3 Jump short if not greater/equal (SF/=OF)
12409 7D cb JNL cb 7,noj=3 Jump short if not less (SF=OF)
12410 7F cb JNLE cb 7,noj=3 Jump short if not less/equal
12412 71 cb JNO cb 7,noj=3 Jump short if notoverflow (OF=0)
12413 7B cb JNP cb 7,noj=3 Jump short if not parity (PF=0)
12414 79 cb JNS cb 7,noj=3 Jump short if not sign (SF=0)
12415 75 cb JNZ cb 7,noj=3 Jump short if not zero (ZF=0)
12416 70 cb JO cb 7,noj=3 Jump short if overflow (OF=1)
12417 7A cb JP cb 7,noj=3 Jump short if parity (PF=1)
12418 7A cb JPE cb 7,noj=3 Jump short if parity even (PF=1)
12419 7B cb JPO cb 7,noj=3 Jump short if parity odd (PF=0)
12420 78 cb JS cb 7,noj=3 Jump short if sign (SF=1)
12421 74 cb JZ cb 7,noj=3 Jump short if zero (ZF=1)
12434 Conditional jumps (except for JCXZ, explained below) test the flags, which
12435 presumably have been set in some meaningful way by a previous instruction.
12436 The conditions for each mnemonic are given in parentheses after each
12437 description above. The terms "less" and "greater" are used for comparing
12438 signed integers; "above" and "below" are used for unsigned integers.
12440 If the given condition is true, then a short jump is made to the label
12441 provided as the operand. Instruction encoding is most efficient when the
12442 target for the conditional jump is in the current code segment and within
12443 -128 to +127 bytes of the first byte of the next instruction.
12444 Alternatively, the opposite sense (e.g., JNZ has opposite sense to that of
12445 JZ) of the conditional jump can skip around an unconditional jump to the
12448 This range is necessary for the assembler to construct a one-byte signed
12449 displacement from the end of the current instruction. If the label is
12450 out-of-range, or if the label is a FAR label, then you must perform a jump
12451 with the opposite condition around an unconditional jump to the non-short
12454 Because there are, in many instances, several ways to interpret a
12455 particular state of the flags, ASM286 provides more than one mnemonic for
12456 most of the conditional jump opcodes. For example, consider that a
12457 programmer who has just compared a character to another in AL might wish to
12458 jump if the two were equal (JE), while another programmer who had just ANDed
12459 AX with a bit field mask would prefer to consider only whether the result
12460 was zero or not (he would use JZ, a synonym for JE).
12462 JCXZ differs from the other conditional jumps in that it actually tests the
12463 contents of the CX register for zero, rather than interrogating the flags.
12464 This instruction is useful following a conditionally repeated string
12465 operation (REPE SCASB, for example) or a conditional loop instruction (such
12466 as LOOPNE TARGETLABEL). These instructions implicitly use a limiting count
12467 in the CX register. Looping (repeating) ends when either the CX register
12468 goes to zero or the condition specified in the instruction (flags indicating
12469 equals in both of the above cases) occurs. JCXZ is useful when the
12470 terminations must be handled differently.
12472 Protected Mode Exceptions
12474 #GP(0) if the offset jumped to is beyond the limits of the code segment.
12476 Real Address Mode Exceptions
12483 Opcode Instruction Clocks
12484 Add one clock for every byte of the next instruction executed. Description
12486 EB cb JMP cb 7 Jump short
12487 EA cd JMP cd 180 Jump to task gate
12488 E9 cw JMP cw 7 Jump near
12489 EA cd JMP cd 11,pm=23 Jump far (4-byte immediate address)
12490 EA cd JMP cd 38 Jump to call gate, same privilege
12491 EA cd JMP cd 175 Jump via Task State Segment
12492 FF /4 JMP ew 7,mem=11 Jump near to EA word
12494 FF /5 JMP ed 15,pm=26 Jump far (4-byte effective address
12495 in memory doubleword)
12496 FF /5 JMP ed 41 Jump to call gate, same privilege
12497 FF /5 JMP ed 178 Jump via Task State Segment
12498 FF /5 JMP ed 183 Jump to task gate
12503 All if a task switch takes place; none if no task switch occurs.
12511 The JMP instruction transfers program control to a different instruction
12512 stream without recording any return information.
12514 For inter-segment jumps, the destination can be a code segment, a call
12515 gate, a task gate, or a Task State Segment. The latter two destinations
12516 cause a complete task switch to take place.
12518 Control transfers within a segment use the JMP cw or JMP cb forms. The
12519 operand is a relative offset added modulo 65536 to the offset of the
12520 instruction that follows the JMP. The result is the new value of IP; the
12521 value of CS is unchanged. The byte operand is sign-extended before it is
12522 added; it can therefore be used to address labels within 128 bytes in either
12523 direction from the next instruction.
12525 Indirect jumps within a segment use the JMP ew form. The contents of the
12526 register or memory operand is an absolute offset, which becomes the new
12527 value of IP. Again, CS is unchanged.
12529 Inter-segment jumps in real address mode simply set IP to the offset part
12530 of the long pointer and set CS to the selector part of the pointer.
12532 In protected mode, inter-segment jumps cause the 80286 to consult the
12533 descriptor addressed by the selector part of the long pointer. The AR byte
12534 of the descriptor determines the type of the destination. (See table B-3
12535 for possible values of the AR byte.) Following are the possible
12538 1. Code segment‘‘The addressability and visibility of the destination
12539 are verified, and CS and IP are loaded with the destination pointer
12542 2. Call gate‘‘The offset part of the destination pointer is ignored.
12543 After checking for validity, the processor jumps to the location
12544 stored in the call gate descriptor.
12546 3. Task gate‘‘The current task's state is saved in its Task State
12547 Segment (TSS), and the TSS named in the task gate is used to load a
12548 new context. The outgoing task is marked not busy, the new TSS is
12549 marked busy, and execution resumes at the point at which the new task
12550 was last suspended.
12552 4. TSS‘‘The current task is suspended and the new task is initiated as
12553 in 3 above except that there is no intervening gate.
12555 Following is the list of checks and actions taken for long jumps in
12559 If indirect then check access of EA doubleword #GP(0) or #SS(0) if limit
12561 Destination selector is not null else #GP(0)
12562 Destination selector index is within its descriptor table limits else
12564 Examine AR byte of destination selector for legal values:
12566 JUMP CONFORMING CODE SEGMENT:
12567 Descriptor DPL must be ¾ CPL else #GP (selector)
12568 Segment must be PRESENT else #NP (selector)
12569 IP must be in code segment limit else #GP(0)
12570 Load CS:IP from destination pointer
12571 Load CS-cache with new segment descriptor
12573 JUMP NONCONFORMING CODE SEGMENT:
12574 RPL of destination selector must be ¾ CPL else #GP (selector)
12575 Descriptor DPL must = CPL else #GP (selector)
12576 Segment must be PRESENT else #NP (selector)
12577 IP must be in code segment limit else #GP(0)
12578 Load CS:IP from destination pointer
12579 Load CS-cache with new segment descriptor
12580 Set RPL field of CS register to CPL
12583 Descriptor DPL must be � CPL else #GP (gate selector)
12584 Descriptor DPL must be � gate selector RPL else #GP (gate selector)
12585 Gate must be PRESENT else #NP (gate selector)
12586 Examine selector to code segment given in call gate descriptor:
12587 Selector must not be null else #GP(0)
12588 Selector must be within its descriptor table limits else
12590 Descriptor AR byte must indicate code segment else #GP (CS selector)
12591 If non-conforming, code segment descriptor DPL must = CPL else
12593 If conforming, then code segment descriptor DPL must be ¾ CPL else
12595 Code Segment must be PRESENT else #NP (CS selector)
12596 IP must be in code segment limit else #GP(0)
12597 Load CS:IP from call gate
12598 Load CS-cache with new code segment
12599 Set RPL of CS to CPL
12602 Gate descriptor DPL must be � CPL else #GP (gate selector)
12603 Gate descriptor DPL must be � gate selector RPL else
12604 #GP (gate selector)
12605 Task Gate must be PRESENT else #NP (gate selector)
12606 Examine selector to TSS, given in Task Gate descriptor:
12607 Must specify global in the local/global bit else #GP (TSS selector)
12608 Index must be within GDT limits else #GP (TSS selector)
12609 Descriptor AR byte must specify available TSS (bottom bits 00001) else
12611 Task State Segment must be PRESENT else #NP (TSS selector)
12612 SWITCH_TASKS without nesting to TSS
12613 IP must be in code segment limit else #GP(0)
12615 JUMP TASK STATE SEGMENT:
12616 TSS DPL must be � CPL else #GP (TSS selector)
12617 TSS DPL must be � TSS selector RPL else #GP (TSS selector)
12618 Descriptor AR byte must specify available TSS (bottom bits 00001) else
12620 Task State Segment must be PRESENT else #NP (TSS selector)
12621 SWITCH_TASKS with nesting to TS.
12622 IP must be in code segment limit else #GP(0)
12626 Protected Mode Exceptions
12628 For NEAR jumps, #GP(0) if the destination offset is beyond the limits of
12629 the current code segment. For FAR jumps, #GP, #NP, #SS, and #TS, as
12630 indicated above. #UD if indirect inter-segment jump operand is a register.
12632 Real Address Mode Exceptions
12634 #UD if indirect inter-segment jump operand is a register.
12637 LAHF‘‘Load Flags into AH Register
12639 Opcode Instruction Clocks Description
12641 9F LAHF 2 Load: AH = flags
12642 SF ZF xx AF xx PF xx CF
12654 The low byte of the flags word is transferred to AH. The bits, from MSB to
12655 LSB, are as follows: sign, zero, indeterminate, auxiliary carry,
12656 indeterminate, parity, indeterminate, and carry. See figure 3-5.
12658 Protected Mode Exceptions
12662 Real Address Mode Exceptions
12667 LAR‘‘Load Access Rights Byte
12669 Opcode Instruction Clocks Description
12671 0F 02 /r LAR rw,ew 14,mem=16 Load: high(rw)= Access Rights
12684 LAR expects the second operand (memory or register word) to contain a
12685 selector. If the associated descriptor is visible at the current privilege
12686 level and at the selector RPL, then the access rights byte of the descriptor
12687 is loaded into the high byte of the first (register) operand, and the low
12688 byte is set to zero. The zero flag is set if the loading was performed
12689 (i.e., the selector index is within the table limit, descriptor DPL � CPL,
12690 and descriptor DPL � selector RPL); the zero flag is cleared otherwise.
12692 Selector operands cannot cause protection exceptions.
12694 Protected Mode Exceptions
12696 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
12697 segments; #SS(0) for an illegal address in the SS segment.
12699 Real Address Mode Exception
12701 INTERRUPT 6; LAR is unrecognized in Real Address mode.
12704 LDS/LES‘‘Load Doubleword Pointer
12706 Opcode Instruction Clocks Description
12708 C5 /r LDS rw,ed 7,pm=21 Load EA doubleword into DS and word register
12709 C4 /r LES rw,ed 7,pm=21 Load EA doubleword into ES and word register
12721 The four-byte pointer at the memory location indicated by the second
12722 operand is loaded into a segment register and a word register. The first
12723 word of the pointer (the offset) is loaded into the register indicated by
12724 the first operand. The last word of the pointer (the selector) is loaded
12725 into the segment register (DS or ES) given by the instruction opcode.
12727 When the segment register is loaded, its associated cache is also loaded.
12728 The data for the cache is obtained from the descriptor table entry for the
12731 A null selector (values 0000-0003) can be loaded into DS or ES without a
12732 protection exception. Any memory reference using such a segment register
12733 value will cause a #GP(0) exception but will not result in a memory
12734 reference. The saved segment register value will be null.
12736 Following is a list of checks and actions taken when loading the DS or ES
12739 If selector is non-null then:
12740 Selector index must be within its descriptor table limits else
12742 Examine descriptor AR byte:
12744 Data segment or readable non-conforming code segment
12745 Descriptor DPL � CPL else #GP (selector)
12746 Descriptor DPL � selector RPL else #GP (selector)
12748 Readable conforming code segment
12749 No DPL, RPL, or CPL checks
12751 Else #GP (selector)
12753 Segment must be present else #NP (selector)
12754 Load registers from operand
12755 Load segment register descriptor cache
12757 If selector is null then:
12758 Load registers from operand
12759 Mark segment register cache as invalid
12761 Protected Mode Exceptions
12763 #GP or #NP, as indicated in the list above. #GP(0) or #SS(0) if operand
12764 lies outside segment limit. #UD if the source operand is a register.
12766 Real Address Mode Exceptions
12768 Interrupt 13 for operand at offset 0FFFFH or 0FFFDH. #UD if the source
12769 operand is a register.
12772 LEA‘‘Load Effective Address Offset
12774 Opcode Instruction Clocks Description
12776 8D /r LEA rw,m 3 Calculate EA offset given by m, place in rw
12788 The effective address (offset part) of the second operand is placed in the
12789 first (register) operand.
12791 Protected Mode Exceptions
12793 #UD if second operand is a register.
12795 Real Address Mode Exceptions
12797 #UD if second operand is a register.
12800 LEAVE‘‘High Level Procedure Exit
12802 Opcode Instruction Clocks Description
12804 C9 LEAVE 5 Set SP to BP, then POP BP
12816 LEAVE is the complementary operation to ENTER; it reverses the effects of
12817 that instruction. By copying BP to SP, LEAVE releases the stack space used
12818 by a procedure for its dynamics and display. The old frame pointer is now
12819 popped into BP, restoring the caller's frame, and a subsequent RET
12820 instruction will follow the back-link and remove any arguments pushed on
12821 the stack for the exiting procedure.
12823 Protected Mode Exceptions
12825 #SS(0) if BP does not point to a location within the current stack segment.
12827 Real Address Mode Exceptions
12829 Interrupt 13 for a word operand at offset 0FFFFH.
12832 LGDT/LIDT‘‘Load Global/Interrupt Descriptor Table Register
12834 Opcode Instruction Clocks Description
12836 0F 01 /2 LGDT m 11 Load m into Global Descriptor Table reg
12837 0F 01 /3 LIDT m 12 Load m into Interrupt Descriptor Table reg
12849 The Global or the Interrupt Descriptor Table Register is loaded from the
12850 six bytes of memory pointed to by the effective address operand (see figure
12851 10-3). The LIMIT field of the descriptor table register loads from the
12852 first word; the next three bytes go to the BASE field of the register; the
12853 last byte is ignored.
12855 LGDT and LIDT appear in operating systems software; they are not used in
12856 application programs. These are the only instructions that directly load a
12857 physical memory address in 80286 protected mode.
12859 Protected Mode Exceptions
12861 #GP(0) if the current privilege level is not 0.
12863 #UD if source operand is a register.
12865 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
12866 segments; #SS(0) for an illegal address in the SS segment.
12868 Real Address Mode Exceptions
12870 These instructions are valid in Real Address mode to allow the power-up
12871 initialization for Protected mode.
12873 Interrupt 13 for a word operand at offset 0FFFFH. #UD if source operand is
12877 LLDT‘‘Load Local Descriptor Table Register
12879 Opcode Instruction Clocks Description
12881 0F 00 /2 LLDT ew 17,mem=19 Load selector ew into Local
12882 Descriptor Table register
12894 The word operand (memory or register) to LLDT should contain a selector
12895 pointing to the Global Descriptor Table. The GDT entry should be a Local
12896 Descriptor Table Descriptor. If so, then the Local Descriptor Table Register
12897 is loaded from the entry. The descriptor cache entries for DS, ES, SS, and
12898 CS are not affected. The LDT field in the TSS is not changed.
12900 The selector operand is allowed to be zero. In that case, the Local
12901 Descriptor Table Register is marked invalid. All descriptor references
12902 (except by LAR, VERR, VERW or LSL instructions) will cause a #GP fault.
12904 LLDT appears in operating systems software; it does not appear in
12905 applications programs.
12907 Protected Mode Exceptions
12909 #GP(0) if the current privilege level is not 0. #GP (selector) if the
12910 selector operand does not point into the Global Descriptor Table, or if the
12911 entry in the GDT is not a Local Descriptor Table. #NP (selector) if LDT
12912 descriptor is not present. #GP(0) for an illegal memory operand effective
12913 address in the CS, DS, or ES segments; #SS(0) for an illegal address in the
12916 Real Address Mode Exceptions
12918 Interrupt 6; LLDT is not recognized in Real Address Mode.
12921 LMSW‘‘Load Machine Status Word
12923 Opcode Instruction Clocks Description
12925 0F 01 /6 LMSW ew 3,mem=6 Load EA word into Machine Status Word
12937 The Machine Status Word is loaded from the source operand. This instruction
12938 may be used to switch to protected mode. If so, then it must be followed by
12939 an intra-segment jump to flush the instruction queue. LMSW will not switch
12940 back to Real Address Mode.
12942 LMSW appears only in operating systems software. It does not appear in
12943 applications programs.
12945 Protected Mode Exceptions
12947 #GP(0) if the current privilege level is not 0. #GP(0) for an illegal
12948 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
12949 an illegal address in the SS segment.
12951 Real Address Mode Exceptions
12953 Interrupt 13 for a word operand at offset 0FFFFH.
12956 LOCK‘‘Assert BUS LOCK Signal
12958 Opcode Instruction Clocks Description
12960 F0 LOCK 0 Assert BUSLOCK signal for the next instruction
12972 LOCK is a prefix that will cause the BUS LOCK signal of the 80286 to be
12973 asserted for the duration of the instruction that it prefixes. In a
12974 multiprocessor environment, this signal should be used to ensure that the
12975 80286 has exclusive use of any shared memory while BUS LOCK is asserted.
12976 The read-modify-write sequence typically used to implement TEST-AND-SET in
12977 the 80286 is the XCHG instruction.
12979 The 80286 LOCK prefix activates the lock signal for the following
12980 instructions: MOVS, INS, and OUTS. XCHG always asserts BUS LOCK regardless
12981 of the presence or absence of the LOCK prefix.
12983 Protected Mode Exceptions
12985 #GP(0) if the current privilege level is bigger (less privileged) than the
12986 I/O privilege level.
12988 Other exceptions may be generated by the subsequent (locked) instruction.
12990 Real Address Mode Exceptions
12992 None. Exceptions may still be generated by the subsequent (locked)
12996 LODS/LODSB/LODSW‘‘Load String Operand
12998 Opcode Instruction Clocks Description
13000 AC LODS mb 5 Load byte [SI] into AL
13001 AD LODS mw 5 Load word [SI] into AX
13002 AC LODSB 5 Load byte DS:[SI] into AL
13003 AD LODSW 5 Load word DS:[SI] into AX
13015 LODS loads the AL or AX register with the memory byte or word at SI. After
13016 the transfer is made, SI is automatically advanced. If the direction flag is
13017 0 (CLD was executed), SI increments; if the direction flag is 1 (STD was
13018 executed), SI decrements. SI increments or decrements by 1 if a byte was
13019 moved; by 2 if a word was moved.
13021 Protected Address Mode Exceptions
13023 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
13024 segments; #SS(0) for an illegal address in the SS segment.
13026 Real Address Mode Exceptions
13028 Interrupt 13 for a word operand at offset 0FFFFH.
13031 LOOP/LOOPcond‘‘Loop Control with CX Counter
13033 Opcode Instruction Clocks Description
13035 E2 cb LOOP cb 8,noj=4 DEC CX; jump short if CX<>0
13036 E1 cb LOOPE cb 8,noj=4 DEC CX; jump short if CX<>E0 and equal
13038 E0 cb LOOPNE cb 8,noj=4 DEC CX; jump short if CX<>E0 and not equal
13040 E0 cb LOOPNZ cb 8,noj=4 DEC CX; jump short if CX<>E0 and ZF=0
13041 E1 cb LOOPZ cb 8,noj=4 DEC CX; jump short if CX<>E0 and zero (ZF=1)
13053 LOOP first decrements the CX register without changing any of the flags.
13054 Then, conditions are checked as given in the description above for the form
13055 of LOOP being used. If the conditions are met, then an intra-segment jump is
13056 made. The destination to LOOP is in the range from 126 (decimal) bytes
13057 before the instruction to 127 bytes beyond the instruction.
13059 The LOOP instructions are intended to provide iteration control and to
13060 combine loop index management with conditional branching. To use the LOOP
13061 instruction you load an unsigned iteration count into CX, then code the LOOP
13062 at the end of a series of instructions to be iterated. The destination of
13063 LOOP is a label that points to the beginning of the iteration.
13065 Protected Address Mode Exceptions
13067 #GP(0) if the offset jumped to is beyond the limits of the current code
13070 Real Address Mode Exceptions
13075 LSL‘‘Load Segment Limit
13077 Opcode Instruction Clocks Description
13079 0F 03 /r LSL rw,ew 14,mem=16 Load: rw = Segment Limit, selector ew
13091 If the descriptor denoted by the selector in the second (memory or
13092 register) operand is visible at the CPL, a word that consists of the limit
13093 field of the descriptor is loaded into the left operand, which must be a
13094 register. The value is the limit field for that segment. The zero flag is
13095 set if the loading was performed (that is, if the selector is non-null, the
13096 selector index is within the descriptor table limits, the descriptor is a
13097 non-conforming segment descriptor with DPL � CPL, and the descriptor DPL �
13098 selector RPL); the zero flag is cleared otherwise.
13100 The LSL instruction returns only the limit field of segments, task state
13101 segments, and local descriptor tables. The interpretation of the limit value
13102 depends on the type of segment.
13104 The selector operand's value cannot result in a protection exception.
13106 Protected Address Mode Exceptions
13108 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
13109 segments; #SS(0) for an illegal address in the SS segment.
13111 Real Address Mode Exceptions
13113 Interrupt 6; LSL is not recognized in Real Address mode.
13116 LTR‘‘Load Task Register
13118 Opcode Instruction Clocks Description
13120 0F 00 /3 LTR ew 17,mem=19 Load EA word into Task Register
13132 The Task Register is loaded from the source register or memory location
13133 given by the operand. The loaded TSS is marked busy. A task switch operation
13136 LTR appears only in operating systems software. It is not used in
13137 applications programs.
13139 Protected Address Mode Exceptions
13141 #GP for an illegal memory operand effective address in the CS, DS, or ES
13142 segments; #SS for an illegal address in the SS segment.
13144 #GP(0) if the current privilege level is not 0. #GP (selector) if the
13145 object named by the source selector is not a TSS or is already busy. #NP
13146 (selector) if the TSS is marked not present.
13148 Real Address Mode Exceptions
13150 Interrupt 6; LTR is not recognized in Real Address mode.
13156 Opcode Instruction Clocks Description
13157 88 /r MOV eb,rb 2,mem=3 Move byte register into EA byte
13158 89 /r MOV ew,rw 2,mem=3 Move word register into EA word
13159 8A /r MOV rb,eb 2,mem=5 Move EA byte into byte register
13160 8B /r MOV rw,ew 2,mem=5 Move EA word into word register
13161 8C /0 MOV ew,ES 2,mem=3 Move ES into EA word
13162 8C /1 MOV ew,CS 2,mem=3 Move CS into EA word
13163 8C /2 MOV ew,SS 2,mem=3 Move SS into EA word
13164 8C /3 MOV ew,DS 2,mem=3 Move DS into EA word
13165 8E /0 MOV ES,mw 5,pm=19 Move memory word into ES
13166 8E /0 MOV ES,rw 2,pm=17 Move word register into ES
13167 8E /2 MOV SS,mw 5,pm=19 Move memory word into SS
13168 8E /2 MOV SS,rw 2,pm=17 Move word register into SS
13169 8E /3 MOV DS,mw 5,pm=19 Move memory word into DS
13170 8E /3 MOV DS,rw 2,pm=17 Move word register into DS
13171 A0 dw MOV AL,xb 5 Move byte variable (offset dw) into AL
13172 A1 dw MOV AX,xw 5 Move word variable (offset dw=) into AX
13173 A2 dw MOV xb,AL 3 Move AL into byte variable (offset dw=)
13174 A3 dw MOV xw,AX 3 Move AX into word register (offset dw=)
13175 B0+ rb db MOV rb,db 2 Move immediate byte into byte register
13176 B8+ rw dw MOV rw,dw 2 Move immediate word into word register
13177 C6 /0 db MOV eb,db 2,mem=3 Move immediate byte into EA byte
13178 C7 /0 dw MOV ew,dw 2,mem=3 Move immediate word into EA word
13191 The second operand is copied to the first operand.
13193 If the destination operand is a segment register (DS, ES, or SS), then the
13194 associated segment register cache is also loaded. The data for the cache is
13195 obtained from the descriptor table entry for the selector given.
13197 A null selector (values 0000-0003) can be loaded into DS and ES registers
13198 without causing a protection exception. Any use of a segment register with a
13199 null selector to address memory will cause #GP(0) exception. No memory
13200 reference will occur.
13202 Any move into SS will inhibit all interrupts until after the execution of
13203 the next instruction.
13205 Following is a listing of the protected-mode checks and actions taken in
13206 the loading of a segment register:
13209 If selector is null then #GP(0)
13210 Selector index must be within its descriptor table limits else
13212 Selector's RPL must equal CPL else #GP (selector)
13213 AR byte must indicate a writable data segment else #GP (selector)
13214 DPL in the AR byte must equal CPL else #GP (selector)
13215 Segment must be marked PRESENT else #SS (selector)
13216 Load SS with selector
13217 Load SS cache with descriptor
13218 If ES or DS is loaded with non-null selector
13219 Selector index must be within its descriptor table limits else
13221 AR byte must indicate data or readable code segment else #GP (selector)
13222 If data or non-conforming code, then both the RPL and the
13223 CPL must be less than or equal to DPL in AR byte else
13225 Segment must be marked PRESENT else #NP (selector)
13226 Load segment register with selector
13227 Load segment register cache with descriptor
13228 If ES or DS is loaded with a null selector:
13229 Load segment register with selector
13230 Clear descriptor valid bit
13232 Real Address Mode Exceptions
13234 Interrupt 13 for a word operand at offset 0FFFFH.
13237 MOVS/MOVSB/MOVSW‘‘Move Data from String to String
13239 Opcode Instruction Clocks Description
13241 A4 MOVS mb,mb 5 Move byte [SI] to ES:[DI]
13242 A5 MOVS mw,mw 5 Move word [SI] to ES:[DI]
13243 A4 MOVSB 5 Move byte DS:[SI] to ES:[DI]
13244 A5 MOVSW 5 Move word DS:[SI] to ES:[DI]
13256 MOVS copies the byte or word at [SI] to the byte or word at ES:[DI]. The
13257 destination operand must be addressable from the ES register; no segment
13258 override is possible. A segment override may be used for the source operand.
13260 After the data movement is made, both SI and DI are automatically advanced.
13261 If the direction flag is 0 (CLD was executed), the registers increment; if
13262 the direction flag is 1 (STD was executed), the registers decrement. The
13263 registers increment or decrement by 1 if a byte was moved; by 2 if a word
13266 MOVS can be preceded by the REP prefix for block movement of CX bytes or
13267 words. Refer to the REP instruction for details of this operation.
13269 Protected Address Mode Exceptions
13271 #GP(0) if the destination is in a non-writable segment. #GP(0) for an
13272 illegal memory operand effective address in the CS, DS, or ES segments;
13273 #SS(0) for an illegal address in the SS segment.
13275 Real Address Mode Exceptions
13277 Interrupt 13 for a word operand at offset 0FFFFH.
13280 MUL‘‘Unsigned Multiplication of AL or AX
13282 Opcode Instruction Clocks Description
13284 F6 /4 MUL eb 13,mem=16 Unsigned multiply (AX = AL * EA byte)
13285 F7 /4 MUL ew 21,mem=24 Unsigned multiply (DXAX = AX * EA word)
13293 Sign, zero, auxiliary carry, parity
13297 If MUL has a byte operand, then the byte is multiplied by AL, and the
13298 result is left in AX. Carry and overflow are set to 0 if AH is 0; they are
13299 set to 1 otherwise.
13301 If MUL has a word operand, then the word is multiplied by AX, and the
13302 result is left in DX:AX. DX contains the high order 16 bits of the product.
13303 Carry and overflow are set to 0 if DX is 0; they are set to 1 otherwise.
13305 Protected Address Mode Exceptions
13307 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
13308 segments; #SS(0) for an illegal address in the SS segment.
13310 Real Address Mode Exceptions
13312 Interrupt 13 for a word operand at offset 0FFFFH.
13315 NEG‘‘Two's Complement Negation
13317 Opcode Instruction Clocks Description
13319 F6 /3 NEG eb 2,mem=7 Two's complement negate EA byte
13320 F7 /3 NEG ew 2,mem=7 Two's complement negate EA word
13324 Overflow, sign, zero, auxiliary carry, parity, carry
13332 The two's complement of the register or memory operand replaces the old
13333 operand value. Likewise, the operand is subtracted from zero, and the result
13334 is placed in the operand.
13336 The carry flag is set to 1 except when the input operand is zero, in which
13337 case the carry flag is cleared to 0.
13339 Protected Address Mode Exceptions
13341 #GP(0) if the result is in a non-writable segment. #GP(0) for an illegal
13342 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
13343 an illegal address in the SS segment.
13345 Real Address Mode Exceptions
13347 Interrupt 13 for a word operand at offset 0FFFFH.
13352 Opcode Instruction Clocks Description
13354 90 NOP 3 No OPERATION
13366 Performs no operation. NOP is a one-byte filler instruction that takes up
13367 space but affects none of the machine context except IP.
13369 Protected Address Mode Exceptions
13373 Real Address Mode Exceptions
13378 NOT‘‘One's Complement Negation
13380 Opcode Instruction Clocks Description
13382 F6 /2 NOT eb 2,mem=7 Reverse each bit of EA byte
13383 F7 /2 NOT ew 2,mem=7 Reverse each bit of EA word
13395 The operand is inverted; that is, every 1 becomes a 0 and vice versa.
13397 Protected Address Mode Exceptions
13399 #GP(0) if the result is in a non-writable segment. #GP(0) for an illegal
13400 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
13401 an illegal address in the SS segment.
13403 Real Address Mode Exceptions
13405 Interrupt 13 for a word operand at offset 0FFFFH.
13408 OR‘‘Logical Inclusive OR
13410 Opcode Instruction Clocks Description
13412 08 /r OR eb,rb 2,mem=7 Logical-OR byte register into EA byte
13413 09 /r OR ew,rw 2,mem=7 Logical-OR word register into EA word
13414 0A /r OR rb,eb 2,mem=7 Logical-OR EA byte into byte register
13415 0B /r OR rw,ew 2,mem=7 Logical-OR EA word into word register
13416 0C db OR AL,db 3 Logical-OR immediate byte into AL
13417 0D dw OR AX,dw 3 Logical-OR immediate word into AX
13418 80 /1 db OR eb,db 3,mem=7 Logical-OR immediate byte into EA byte
13419 81 /1 dw OR ew,dw 3,mem=7 Logical-OR immediate word into EA word
13423 Overflow=0, sign, zero, parity, carry=0
13431 This instruction computes the inclusive OR of the two operands. Each bit of
13432 the result is 0 if both corresponding bits of the operands are 0; each bit
13433 is 1 otherwise. The result is placed in the first operand.
13435 Protected Address Mode Exceptions
13437 #GP(0) if the result is in a non-writable segment. #GP(0) for an illegal
13438 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
13439 an illegal address in the SS segment.
13441 Real Address Mode Exceptions
13443 Interrupt 13 for a word operand at offset 0FFFFH.
13446 OUT‘‘Output to Port
13448 Opcode Instruction Clocks Description
13450 E6 db OUT db,AL 3 Output byte AL to immediate port number db
13451 E7 db OUT db,AX 3 Output word AX to immediate port number db
13452 EE OUT DX,AL 3 Output byte AL to port number DX
13453 EF OUT DX,AX 3 Output word AX to port number DX
13465 OUT transfers a data byte or data word from the register (AL or AX) given
13466 as the second operand to the output port numbered by the first operand. You
13467 can output to any port from 0-65535 by placing the port number in the DX
13468 register then using an OUT instruction with DX as the first operand. If the
13469 instruction contains an 8-bit port ID, that value is zero-extended to 16
13472 Intel reserves I/O port addresses 00F8H through 00FFH; these addresses
13473 should not be used.
13475 Protected Address Mode Exceptions
13477 #GP(0) if the current privilege level is bigger (has less privilege) than
13478 IOPL, which is the privilege level found in the flags register.
13480 Real Address Mode Exceptions
13485 OUTS/OUTSB/OUTSW‘‘Output String to Port
13487 Opcode Instruction Clocks Description
13489 6E OUTS DX,eb 5 Output byte [SI] to port number DX
13490 6F OUTS DX,ew 5 Output word [SI] to port number DX
13491 6E OUTSB 5 Output byte DS:[SI] to port number DX
13492 6F OUTSW 5 Output word DS:[SI] to port number DX
13503 OUTS transfers data from the memory byte or word at SI to the output port
13504 numbered by the DX register.
13506 OUTS does not allow the specification of the port number as an immediate
13507 value. The port must be addressed through the DX register.
13509 After the transfer is made, SI is automatically advanced. If the direction
13510 flag is 0 (CLD was executed), SI increments; if the direction flag is 1 (STD
13511 was executed), SI decrements. SI increments or decrements by 1 if a byte was
13512 moved; by 2 if a word was moved.
13514 OUTS can be preceded by the REP prefix for block output of CX bytes or
13515 words. Refer to the REP instruction for details of this operation.
13517 Intel reserves I/O port addresses 00F8H through 00FFH; these addresses
13518 should not be used.
13520 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
13522 Not all output devices can handle the rate at which this instruction
13524 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
13526 Protected Mode Exceptions
13528 #GP(0) if CPL > IOPL. #GP(0) for an illegal memory operand effective
13529 address in the CS, DS, or ES segments; #SS(0) for an illegal address in the
13532 Real Address Mode Exceptions
13534 Interrupt 13 for a word operand at offset 0FFFFH.
13537 POP‘‘Pop a Word from the Stack
13539 Opcode Instruction Clocks Description
13541 1F POP DS 5,pm=20 Pop top of stack into DS
13542 07 POP ES 5,pm=20 Pop top of stack into ES
13543 17 POP SS 5,pm=20 Pop top of stack into SS
13544 8F /0 POP mw 5 Pop top of stack into memory word
13545 58+rw POP rw 5 Pop top of stack into word register
13557 The word on the top of the 80286 stack, addressed by SS:SP, replaces the
13558 previous contents of the memory, register, or segment register operand. The
13559 stack pointer SP is incremented by 2 to point to the new top of stack.
13561 If the destination operand is another segment register (DS, ES, or SS), the
13562 value popped must be a selector. In protected mode, loading the selector
13563 initiates automatic loading of the descriptor information associated with
13564 that selector into the hidden part of the segment register; loading also
13565 initiates validation of both the selector and the descriptor information.
13567 A null value (0000-0003) may be loaded into the DS or ES register without
13568 causing a protection exception. Attempts to reference memory using a segment
13569 register with a null value will cause #GP(0) exception. No memory reference
13570 will occur. The saved value of the segment register will be null.
13572 A POP SS instruction will inhibit all interrupts, including NMI, until
13573 after the execution of the next instruction. This permits a POP SP
13574 instruction to be performed first.
13576 Following is a listing of the protected-mode checks and actions taken in
13577 the loading of a segment register:
13580 If selector is null then #GP(0)
13581 Selector index must be within its descriptor table limits else #GP
13583 Selector's RPL must equal CPL else #GP (selector)
13584 AR byte must indicate a writable data segment else #GP (selector)
13585 DPL in the AR byte must equal CPL else #GP (selector)
13586 Segment must be marked PRESENT else #SS (selector)
13587 Load SS register with selector
13588 Load SS cache with descriptor
13589 If ES or DS is loaded with non-null selector:
13590 AR byte must indicate data or readable code segment else #GP (selector)
13591 If data or non-conforming code, then both the RPL and the
13592 CPL must be less than or equal to DPL in AR byte else
13594 Segment must be marked PRESENT else #NP (selector)
13595 Load segment register with selector
13596 Load segment register cache with descriptor
13597 If ES or DS is loaded with a null selector:
13598 Load segment register with selector
13599 Clear valid bit in cache
13601 Protected Mode Exceptions
13603 If a segment register is being loaded, #GP, #SS, and #NP, as described in
13606 Otherwise, #SS(0) if the current top of stack is not within the stack
13609 #GP(0) if the destination is in a non-writable segment. #GP(0) for an
13610 illegal memory operand effective address in the CS, DS, or ES segments;
13611 #SS(0) for an illegal address in the SS segment.
13613 Real Address Mode Exceptions
13615 Interrupt 13 for a word operand at offset 0FFFFH.
13618 POPA‘‘Pop All General Registers
13620 Opcode Instruction Clocks Description
13622 61 POPA 19 Pop in order: DI,SI,BP,SP,BX,DX,CX,AX
13634 POPA pops the eight general registers given in the description above,
13635 except that the SP value is discarded instead of loaded into SP. POPA
13636 reverses a previous PUSHA, restoring the general registers to their values
13637 before PUSHA was executed. The first register popped is DI.
13639 Protected Mode Exceptions
13641 #SS(0) if the starting or ending stack address is not within the stack
13644 Real Address Mode Exceptions
13646 Interrupt 13 for a word operand at offset 0FFFFH.
13649 POPF‘‘Pop from Stack into the Flags Register
13651 Opcode Instruction Clocks Description
13653 9D POPF 5 Pop top of stack into flags register
13657 Entire flags register is popped from stack
13665 The top of the 80286 stack, pointed to by SS:SP, is copied into the 80286
13666 flags register. The stack pointer SP is incremented by 2 to point to the new
13667 top of stack. The flags, from the top bit (bit 15) to the bottom (bit 0),
13668 are as follows: undefined, nested task, I/O privilege level (2 bits),
13669 overflow, direction, interrupts enabled, trap, sign, zero, undefined,
13670 auxiliary carry, undefined, parity, undefined, and carry.
13672 The I/O privilege level will be altered only when executing at privilege
13673 level 0. The interrupt enable flag will be altered only when executing at a
13674 level at least as privileged as the I/O privilege level. If you execute a
13675 POPF instruction with insufficient privilege, there will be no exception
13676 nor will the privileged bits be changed.
13678 Protected Mode Exceptions
13680 #SS(0) if the top of stack is not within the stack segment.
13682 Real Address Mode Exceptions
13684 Interrupt 13 for a word operand at 0FFFFH.
13686 In real mode the NT and IOPL bits will not be modified.
13689 PUSH‘‘Push a Word onto the Stack
13691 Opcode Instruction Clocks Description
13693 06 PUSH ES 3 Push ES
13694 0E PUSH CS 3 Push CS
13695 16 PUSH SS 3 Push SS
13696 1E PUSH DS 3 Push DS
13697 50+ rw PUSH rw 3 Push word register
13698 FF /6 PUSH mw 5 Push memory word
13699 68 dw PUSH dw 3 Push immediate word
13700 6A db PUSH db 3 Push immediate sign-extended byte
13712 The stack pointer SP is decremented by 2, and the operand is placed on the
13713 new top of stack, which is pointed to by SS:SP.
13715 The 80286 PUSH SP instruction pushes the value of SP as it existed before
13716 the instruction. This differs from the 8086, which pushes the new
13717 (decremented by 2) value.
13719 Protected Mode Exceptions
13721 #SS(0) if the new value of SP is outside the stack segment limit.
13723 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
13724 segments; #SS(0) for an illegal address in the SS segment.
13726 Real Address Mode Exceptions
13728 None; the 80286 will shut down if SP = 1 ‘‘due to lack of stack space.
13731 PUSHA‘‘Push All General Registers
13733 Opcode Instruction Clocks Description
13735 60 PUSHA 17 Push in order: AX,CX,DX,BX,original
13748 PUSHA saves the registers noted above on the 80286 stack. The stack pointer
13749 SP is decremented by 16 to hold the 8 word values. Since the registers are
13750 pushed onto the stack in the order in which they were given, they will
13751 appear in the 16 new stack bytes in the reverse order. The last register
13754 Protected Mode Exceptions
13756 #SS(0) if the starting or ending address is outside the stack segment
13759 Real Address Mode Exceptions
13761 The 80286 will shut down if SP = 1, 3, or 5 before executing PUSHA. If SP =
13762 7, 9, 11, 13, or 15, exception 13 will occur.
13765 PUSHF‘‘Push Flags Register onto the Stack
13767 Opcode Instruction Clocks Description
13769 9C PUSHF 3 Push flags register
13781 The stack pointer SP is decremented by 2, and the 80286 flags register is
13782 copied to the new top of stack, which is pointed to by SS:SP. The flags,
13783 from the top bit (15) to the bottom bit (0), are as follows: undefined,
13784 nested task, I/O privilege level (2 bits), overflow, direction, interrupts
13785 enabled, trap, sign, zero, undefined, auxiliary carry, undefined, parity,
13786 undefined, and carry.
13788 Protected Mode Exceptions
13790 #SS(0) if the new value of SP is outside the stack segment limit.
13792 Real Address Mode Exceptions
13794 None; the 80286 will shut down if SP=1 due‘‘to lack of stack space.
13797 RCL/RCR/ROL/ROR‘‘Rotate Instructions
13800 Opcode Instruction Clocks-N
13801 Add 1 clock to the times shown for each rotate made Description
13802 D0 /2 RCL eb,1 2,mem=7 Rotate 9-bits (CF, EA byte) left once
13803 D2 /2 RCL eb,CL 5,mem=8 Rotate 9-bits (CF, EA byte) left CL times
13804 C0 /2 db RCL eb,db 5,mem=8 Rotate 9-bits (CF, EA byte) left db times
13805 D1 /2 RCL ew,1 2,mem=7 Rotate 17-bits (CF, EA word) left once
13806 D3 /2 RCL ew,CL 5,mem=8 Rotate 17-bits (CF, EA word) left CL times
13807 C1 /2 db RCL ew,db 5,mem=8 Rotate 17-bits (CF, EA word) left db times
13808 D0 /3 RCR eb,1 2,mem=7 Rotate 9-bits (CF, EA byte) right once
13809 D2 /3 RCR eb,CL 5,mem=8 Rotate 9-bits (CF, EA byte) right CL times
13810 C0 /3 db RCR eb,db 5,mem=8 Rotate 9-bits (CF, EA byte) right db times
13811 D1 /3 RCR ew,1 2,mem=7 Rotate 17-bits (CF, EA word) right once
13812 D3 /3 RCR ew,CL 5,mem=8 Rotate 17-bits (CF, EA word) right CL times
13813 C1 /3 db RCR ew,db 5,mem=8 Rotate 17-bits (CF, EA word) right db times
13814 D0 /0 ROL eb,1 2,mem=7 Rotate 8-bit EA byte left once
13815 D2 /0 ROL eb,CL 5,mem=8 Rotate 8-bit EA byte left CL times
13816 C0 /0 db ROL eb,db 5,mem=8 Rotate 8-bit EA byte left db times
13817 D1 /0 ROL ew,1 2,mem=7 Rotate 16-bit EA word left once
13818 D3 /0 ROL ew,CL 5,mem=8 Rotate 16-bit EA word left CL times
13819 C1 /0 db ROL ew,db 5,mem=8 Rotate 16-bit EA word left db times
13820 D0 /1 ROR eb,1 2,mem=7 Rotate 8-bit EA byte right once
13821 D2 /1 ROR eb,CL 5,mem=8 Rotate 8-bit EA byte right CL times
13822 C0 /1 db ROR eb,db 5,mem=8 Rotate 8-bit EA byte right db times
13823 D1 /1 ROR ew,1 2,mem=7 Rotate 16-bit EA word right once
13824 D3 /1 ROR ew,CL 5,mem=8 Rotate 16-bit EA word right CL times
13825 C1 /1 db ROR ew,db 5,mem=8 Rotate 16-bit EA word right db times
13830 Overflow (only for single rotates), carry
13834 Overflow for multi-bit rotates
13838 Each rotate instruction shifts the bits of the register or memory operand
13839 given. The left rotate instructions shift all of the bits upward, except for
13840 the top bit, which comes back around to the bottom. The right rotate
13841 instructions do the reverse: the bits shift downward, with the bottom bit
13842 coming around to the top.
13844 For the RCL and RCR instructions, the carry flag is part of the rotated
13845 quantity. RCL shifts the carry flag into the bottom bit and shifts the top
13846 bit into the carry flag; RCR shifts the carry flag into the top bit and
13847 shifts the bottom bit into the carry flag. For the ROL and ROR
13848 instructions, the original value of the carry flag is not a part of the
13849 result; nonetheless, the carry flag receives a copy of the bit that was
13850 shifted from one end to the other.
13852 The rotate is repeated the number of times indicated by the second operand,
13853 which is either an immediate number or the contents of the CL register. To
13854 reduce the maximum execution time, the 80286 does not allow rotation counts
13855 greater than 31. If a rotation count greater than 31 is attempted, only the
13856 bottom five bits of the rotation are used. The 8086 does not mask rotate
13859 The overflow flag is set only for the single-rotate (second operand = 1)
13860 forms of the instructions. The OF bit is set to be accurate if a shift of
13861 length 1 is done. Since it is undefined for all other values, including a
13862 zero shift, it can always be set for the count-of-1 case regardless of the
13863 actual count. For left shifts/rotates, the CF bit after the shift is XORed
13864 with the high-order result bit. For right shifts/rotates, the high-order
13865 two bits of the result are XORed to get OF. Neither flag bit is modified
13866 when the count value is zero.
13868 Protected Mode Exceptions
13870 #GP(0) if the result is in a non-writable segment. #GP(0) for an illegal
13871 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
13872 an illegal address in the SS segment.
13874 Real Address Mode Exceptions
13876 Interrupt 13 for a word operand at offset 0FFFFH.
13879 REP/REPE/REPNE‘‘Repeat Following String Operation
13882 Opcode Instruction Clocks
13883 N denotes the number of iterations actually executed. Description
13884 F3 6C REP INS eb,DX 5+4 CX Input CX bytes from port DX into ES:[DI]
13885 F3 6D REP INS ew,DX 5+4 CX Input CX words from port DX into ES:[DI]
13886 F3 6C REP INSB 5+4 CX Input CX bytes from port DX into ES:[DI]
13887 F3 6D REP INSW 5+4 CX Input CX words from port DX into ES:[DI]
13888 F3 A4 REP MOVS mb,mb 5+4 CX Move CX bytes from [SI] to ES:[DI]
13889 F3 A5 REP MOVS mw,mw 5+4 CX Move CX words from [SI] to ES:[DI]
13890 F3 A4 REP MOVSB 5+4 CX Move CX bytes from DS:[SI] to ES:[DI]
13891 F3 A5 REP MOVSW 5+4 CX Move CX words from DS:[SI] to ES:[DI]
13892 F3 6E REP OUTS DX,eb 5+4 CX Output CX bytes from [SI] to port DX
13893 F3 6F REP OUTS DX,ew 5+4 CX Output CX words from [SI] to port DX
13894 F3 6E REP OUTSB 5+4 CX Output CX bytes from DS:[SI] to port DX
13895 F3 6F REP OUTSW 5+4 CX Output CX words from DS:[SI] to port DX
13896 F3 AA REP STOS mb 4+3 CX Fill CX bytes at ES:[DI] with AL
13897 F3 AB REP STOS mw 4+3 CX Fill CX words at ES:[DI] with AX
13898 F3 AA REP STOSB 4+3 CX Fill CX bytes at ES:[DI] with AL
13899 F3 AB REP STOSW 4+3 CX Fill CX words at ES:[DI] with AX
13900 F3 A6 REPE CMPS mb,mb 5+9 N Find nonmatching bytes in
13902 F3 A7 REPE CMPS mw,mw 5+9 N Find nonmatching words in
13904 F3 A6 REPE CMPSB 5+9 N Find nonmatching bytes in ES:[DI]
13906 F3 A7 REPE CMPSW 5+9 N Find nonmatching words in ES:[DI]
13908 F3 AE REPE SCAS mb 5+8 N Find non-AL byte starting at ES:[DI]
13909 F3 AF REPE SCAS mw 5+8 N Find non-AX word starting at ES:[DI]
13910 F3 AE REPE SCASB 5+8 N Find non-AL byte starting at ES:[DI]
13911 F3 AF REPE SCASW 5+8 N Find non-AX word starting at ES:[DI]
13912 F2 A6 REPNE CMPS mb,mb 5+9 N Find matching bytes in
13914 F2 A7 REPNE CMPS mw,mw 5+9 N Find matching words in
13916 F2 A6 REPNE CMPSB 5+9 N Find matching bytes in ES:[DI]
13918 F2 A7 REPNE CMPSW 5+9 N Find matching words in ES:[DI]
13920 F2 AE REPNE SCAS mb 5+8 N Find AL, starting at ES:[DI]
13921 F2 AF REPNE SCAS mw 5+8 N Find AX, starting at ES:[DI]
13922 F2 AE REPNE SCASB 5y+8 N Find AL, starting at ES:[DI]
13923 F2 AF REPNE SCASW 5+8 N Find AX, starting at ES:[DI]
13928 By CMPS and SCAS, none by REP
13936 REP, REPE, and REPNE are prefix operations. These prefixes cause the string
13937 instruction that follows to be repeated CX times or (for REPE and REPNE)
13938 until the indicated condition in the zero flag is no longer met. Thus, REPE
13939 stands for "Repeat while equal," REPNE for "Repeat while not equal."
13941 The REP prefixes make sense only in the contexts listed above. They cannot
13942 be applied to anything other than string operations.
13944 Synonymous forms of REPE and REPNE are REPZ and REPNZ, respectively.
13946 The REP prefixes apply only to one string instruction at a time. To repeat
13947 a block of instructions, use a LOOP construct.
13949 The precise action for each iteration is as follows:
13951 1. Check the CX register. If it is zero, exit the iteration and move to
13952 the next instruction.
13954 2. Acknowledge any pending interrupts.
13956 3. Perform the string operation once.
13958 4. Decrement CX by 1; no flags are modified.
13960 5. If the string operation is SCAS or CMPS, check the zero flag. If the
13961 repeat condition does not hold, then exit the iteration and move to
13962 the next instruction. Exit if the prefix is REPE and ZF=0 (the last
13963 comparison was not equal), or if the prefix is REPNE and ZF=1 (the
13964 last comparison was equal).
13966 6. Go to step 1 for the next iteration.
13968 As defined by the individual string-ops, the direction of movement through
13969 the block is determined by the direction flag. If the direction flag is 1
13970 (STD was executed), SI and/or DI start at the end of the block and move
13971 backward; if the direction flag is 0 (CLD was executed), SI and/or DI start
13972 at the beginning of the block and move forward.
13974 For repeated SCAS and CMPS operations the repeat can be exited for one of
13975 two different reasons: the CX count can be exhausted or the zero flag can
13976 fail the repeat condition. Your code will probably want to distinguish
13977 between the two cases. It can do so via either the JCXZ instruction or the
13978 conditional jumps that test the zero flag (JZ, JNZ, JE, and JNE).
13980 Not all input/output ports can handle the rate at which the repeated I/O
13981 instructions execute.
13983 Protected Mode Exceptions
13985 None by REP; exceptions can be generated when the string-op is executed.
13987 Real Address Mode Exceptions
13989 None by REP; exceptions can be generated when the string-op is executed.
13992 RET‘‘Return from Procedure
13994 Opcode Instruction Clocks
13995 Add 1 clock for each byte in the next instruction executed. Description
13997 CB RET 15,pm=25 Return to far caller, same privilege
13998 CB RET 55 Return, lesser privilege, switch stacks
13999 C3 RET 11 Return to near caller, same privilege
14000 CA dw RET dw 15,pm=25 RET (far), same privilege, pop dw bytes
14001 CA dw RET dw 55 RET (far), lesser privilege, pop dw bytes
14002 C2 dw RET dw 11 RET (near), same privilege, pop dw bytes
14015 RET transfers control to a return address located on the stack. The address
14016 is usually placed on the stack by a CALL instruction; in that case, the
14017 return is made to the instruction that follows the CALL.
14019 There is an optional numeric parameter to RET. It gives the number of stack
14020 bytes to be released after the return address is popped. These bytes are
14021 typically used as input parameters to the procedure called.
14023 For the intra-segment return, the address on the stack is a 2-byte quantity
14024 popped into IP. The CS register is unchanged.
14026 For the inter-segment return, the address on the stack is a 4-byte-long
14027 pointer. The offset is popped first, followed by the selector. In real
14028 address mode, CS and IP are directly loaded.
14030 In protected mode, an inter-segment return causes the processor to consult
14031 the descriptor addressed by the return selector. The AR byte of the
14032 descriptor must indicate a code segment of equal or less privilege (of
14033 greater or equal numeric value) than the current privilege level. Returns
14034 to a lesser privilege level cause the stack to be reloaded from the value
14035 saved beyond the parameter block.
14037 The DS and ES segment registers may be set to zero by the inter-segment RET
14038 instruction. If these registers refer to segments which cannot be used by
14039 the new privilege level, they are set to zero to prevent unauthorized
14042 The following list of checks and actions describes the protected-mode
14043 inter-segment return in detail.
14046 Second word on stack must be within stack limits else #SS(0)
14047 Return selector RPL must be � CPL else #GP (return selector)
14048 If return selector RPL = CPL then
14049 RETURN TO SAME LEVEL:
14050 Return selector must be non-null else #GP(0)
14051 Selector index must be within its descriptor table limits else
14053 Descriptor AR byte must indicate code segment else #GP (selector)
14054 If non-conforming then code segment DPL must equal CPL else
14056 If conforming then code segment DPL must be ¾ CPL else #GP (selector)
14057 Code segment must be PRESENT else #NP (selector)
14058 Top word on stack must be within stack limits else #SS(0)
14059 IP must be in code segment limit else #GP(0)
14060 Load CS:IP from stack
14061 Load CS-cache with descriptor
14062 Increment SP by 4 plus the immediate offset if it exists
14064 RETURN TO OUTER PRIVILEGE LEVEL:
14065 Top (8+immediate) bytes on stack must be within stack limits else #SS(0)
14066 Examine return CS selector (at SP+2) and associated descriptor:
14067 Selector must be non-null else #GP(0)
14068 Selector index must be within its descriptor table limits else
14070 Descriptor AR byte must indicate code segment else #GP (selector)
14071 If non-conforming then code segment DPL must equal return selector
14072 RPL else #GP (selector)
14073 If conforming then code segment DPL must be ¾ return selector RPL
14074 else #GP (selector)
14075 Segment must be PRESENT else #NP (selector)
14076 Examine return SS selector (at SP+6+imm) and associated descriptor:
14077 Selector must be non-null else #GP(0)
14078 Selector index must be within its descriptor table limits else
14080 Selector RPL must equal the RPL of the return CS selector else
14082 Descriptor AR byte must indicate a writable data segment else
14084 Descriptor DPL must equal the RPL of the return CS selector else
14086 Segment must be PRESENT else #SS (selector)
14087 IP must be in code segment limit else # GP(0)
14088 Set CPL to the RPL of the return CS selector
14089 Load CS:IP from stack
14091 Increment SP by 4 plus the immediate offset if it exists
14092 Load SS:SP from stack
14093 Load the CS-cache with the return CS descriptor
14094 Load the SS-cache with the return SS descriptor
14095 For each of ES and DS:
14096 If the current register setting is not valid for the outer level,
14097 set the register to null (selector = AR = 0)
14098 To be valid, the register setting must satisfy the following
14100 Selector index must be within descriptor table limits
14101 Descriptor AR byte must indicate data or readable code segment
14102 If segment is data or non-conforming code, then:
14103 DPL must be � CPL, or
14106 Protected Mode Exceptions
14108 #GP, #NP, or #SS, as described in the above listing.
14110 Real Address Mode Exceptions
14112 Interrupt 13 if the stack pop wraps around from 0FFFFH to 0.
14115 SAHF‘‘Store AH into Flags
14117 Opcode Instruction Clocks Description
14119 9E SAHF 2 Store AH into flags
14120 SF ZF xx AF xx PF xx CF
14124 Sign, zero, auxiliary carry, parity, carry
14132 The flags listed above are loaded with values from the AH register, from
14133 bits 7, 6, 4, 2, and 0, respectively.
14135 Protected Mode Exceptions
14139 Real Address Mode Exceptions
14144 SAL/SAR/SHL/SHR‘‘Shift Instructions
14146 Opcode Instruction Clocks-N
14147 Add 1 clock to the times shown for each shift performed Description
14149 D0 /4 SAL eb,1 2,mem=7 Multiply EA byte by 2, once
14150 D2 /4 SAL eb,CL 5,mem=8 Multiply EA byte by 2, CL times
14151 C0 /4 db SAL eb,db 5,mem=8 Multiply EA byte by 2, db times
14152 D1 /4 SAL ew,1 2,mem=7 Multiply EA word by 2, once
14153 D3 /4 SAL ew,CL 5,mem=8 Multiply EA word by 2, CL times
14154 C1 /4 db SAL ew,db 5,mem=8 Multiply EA word by 2, db times
14155 D0 /7 SAR eb,1 2,mem=7 Signed divide EA byte by 2, once
14156 D2 /7 SAR eb,CL 5,mem=8 Signed divide EA byte by 2, CL times
14157 C0 /7 db SAR eb,db 5,mem=8 Signed divide EA byte by 2, db times
14158 D1 /7 SAR ew,1 2,mem=7 Signed divide EA word by 2, once
14159 D3 /7 SAR ew,CL 5,mem=8 Signed divide EA word by 2, CL times
14160 C1 /7 db SAR ew,db 5,mem=8 Signed divide EA word by 2, db times
14161 D0 /5 SHR eb,1 2,mem=7 Unsigned divide EA byte by 2, once
14162 D2 /5 SHR eb,CL 5,mem=8 Unsigned divide EA byte by 2, CL times
14163 C0 /5 db SHR eb,db 5,mem=8 Unsigned divide EA byte by 2, db times
14164 D1 /5 SHR ew,1 2,mem=7 Unsigned divide EA word by 2, once
14165 D3 /5 SHR ew,CL 5,mem=8 Unsigned divide EA word by 2, CL times
14170 Overflow (only for single-shift form), carry, zero, parity, sign
14174 Auxiliary carry; also overflow for multibit shifts (only).
14178 SAL (or its synonym SHL) shifts the bits of the operand upward. The
14179 high-order bit is shifted into the carry flag, and the low-order bit is set
14182 SAR and SHR shift the bits of the operand downward. The low-order bit is
14183 shifted into the carry flag. The effect is to divide the operand by 2. SAR
14184 performs a signed divide: the high-order bit remains the same. SHR performs
14185 an unsigned divide: the high-order bit is set to 0.
14187 The shift is repeated the number of times indicated by the second operand,
14188 which is either an immediate number or the contents of the CL register. To
14189 reduce the maximum execution time, the 80286 does not allow shift counts
14190 greater than 31. If a shift count greater than 31 is attempted, only the
14191 bottom five bits of the shift count are used. The 8086 uses all 8 bits of
14194 The overflow flag is set only if the single-shift forms of the instructions
14195 are used. For left shifts, it is set to 0 if the high bit of the answer is
14196 the same as the result carry flag (i.e., the top two bits of the original
14197 operand were the same); it is set to 1 if they are different. For SAR it is
14198 set to 0 for all single shifts. For SHR, it is set to the high-order bit of
14199 the original operand. Neither flag bit is modified when the count value is
14202 Protected Mode Exceptions
14204 #GP(0) if the operand is in a non-writable segment. #GP(0) for an illegal
14205 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
14206 an illegal address in the SS segment.
14208 Real Address Mode Exceptions
14210 Interrupt 13 for a word operand at offset 0FFFFH.
14213 SBB‘‘Integer Subtraction With Borrow
14215 Opcode Instruction Clocks Description
14217 18 /r SBB eb,rb 2,mem=7 Subtract with borrow byte
14218 register from EA byte
14219 19 /r SBB ew,rw 2,mem=7 Subtract with borrow word
14220 register from EA word
14221 1A /r SBB rb,eb 2,mem=7 Subtract with borrow EA byte
14223 1B /r SBB rw,ew 2,mem=7 Subtract with borrow EA word
14225 1C db SBB AL,db 3 Subtract with borrow imm.
14227 1D dw SBB AX,dw 3 Subtract with borrow imm.
14229 80 /3 db SBB eb,db 3,mem=7 Subtract with borrow imm. byte
14231 81 /3 dw SBB ew,dw 3,mem=7 Subtract with borrow imm. word
14233 83 /3 db SBB ew,db 3,mem=7 Subtract with borrow imm. byte
14238 Overflow, sign, zero, auxiliary carry, parity, carry
14246 The second operand is added to the carry flag and the result is subtracted
14247 from the first operand. The first operand is replaced with the result of the
14248 subtraction, and the flags are set accordingly.
14250 When a byte-immediate value is subtracted from a word operand, the
14251 immediate value is first sign-extended.
14253 Protected Mode Exceptions
14255 #GP(0) if the result is in a non-writable segment. #GP(0) for an illegal
14256 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
14257 an illegal address in the SS segment.
14259 Real Address Mode Exceptions
14261 Interrupt 13 for a word operand at offset 0FFFFH.
14264 SCAS/SCASB/SCASW‘‘Compare String Data
14266 Opcode Instruction Clocks Description
14268 AE SCAS mb 7 Compare bytes AL - ES:[DI], advance DI
14269 AF SCAS mw 7 Compare words AX - ES:[DI], advance DI
14270 AE SCASB 7 Compare bytes AL - ES:[DI], advance DI
14271 AF SCASW 7 Compare words AX - ES:[DI], advance DI
14275 Overflow, sign, zero, auxiliary carry, parity, carry
14283 SCAS subtracts the memory byte or word at ES:DI from the AL or AX register.
14284 The result is discarded; only the flags are set. The operand must be
14285 addressable from the ES register; no segment override is possible.
14287 After the comparison is made, DI is automatically advanced. If the
14288 direction flag is 0 (CLD was executed), DI increments; if the direction flag
14289 is 1 (STD was executed), DI decrements. DI increments or decrements by 1 if
14290 bytes were compared; by 2 if words were compared.
14292 SCAS can be preceded by the REPE or REPNE prefix for a block search of CX
14293 bytes or words. Refer to the REP instruction for details of this operation.
14295 Protected Mode Exceptions
14297 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
14298 segments; #SS(0) for an illegal address in the SS segment.
14300 Real Address Mode Exceptions
14302 Interrupt 13 for a word operand at offset 0FFFFH.
14305 SGDT/SIDT‘‘Store Global/Interrupt Descriptor Table Register
14307 Opcode Instruction Clocks Description
14309 0F 01 /0 SGDT m 11 Store Global Descriptor Table register
14311 0F 01 /1 SIDT m 12 Store Interrupt Descriptor Table
14324 The contents of the descriptor table register are copied to six bytes of
14325 memory indicated by the operand. The LIMIT field of the register goes to the
14326 first word at the effective address; the next three bytes get the BASE field
14327 of the register; and the last byte is undefined.
14329 SGDT and SIDT appear only in operating systems software; they are not used
14330 in applications programs.
14332 Protected Mode Exceptions
14334 #UD if the destination operand is a register. #GP(0) if the destination is
14335 in a non-writable segment. #GP(0) for an illegal memory operand effective
14336 address in the CS, DS, or ES segments; #SS(0) for an illegal address in the
14339 Real Address Mode Exceptions
14341 These instructions are valid in Real Address mode to facilitate power-up or
14342 to reset initialization prior to entering Protected mode.
14344 #UD if the destination operand is a register. Interrupt 13 for a word
14345 operand at offset 0FFFFH.
14348 SLDT‘‘Store Local Descriptor Table Register
14350 Opcode Instruction Clocks Description
14352 0F 00 /0 SLDT ew 2,mem=3 Store Local Descriptor Table register to
14365 The Local Descriptor Table register is stored in the 2-byte register or
14366 memory location indicated by the effective address operand. This register is
14367 a selector that points into the Global Descriptor Table.
14369 SLDT appears only in operating systems software. It is not used in
14370 applications programs.
14372 Protected Mode Exceptions
14374 #GP(0) if the destination is in a non-writable segment. #GP(0) for an
14375 illegal memory operand effective address in the CS, DS, or ES segments;
14376 #SS(0) for an illegal address in the SS segment.
14378 Real Address Mode Exceptions
14380 Interrupt 6; SLDT is not recognized in Real Address mode.
14383 SMSW‘‘Store Machine Status Word
14385 Opcode Instruction Clocks Description
14387 0F 01 /4 SMSW ew 2,mem=3 Store Machine Status Word to EA word
14399 The Machine Status Word is stored in the 2-byte register or memory location
14400 indicated by the effective address operand.
14402 Protected Mode Exceptions
14404 #GP(0) if the destination is in a non-writable segment. #GP(0) for an
14405 illegal memory operand effective address in the CS, DS, or ES segments;
14406 #SS(0) for an illegal address in the SS segment.
14408 Real Address Mode Exceptions
14410 Interrupt 13 for a word operand at offset 0FFFFH.
14413 STC‘‘Set Carry Flag
14415 Opcode Instruction Clocks Description
14417 F9 STC 2 Set carry flag
14429 The carry flag is set to 1.
14431 Protected Mode Exceptions
14435 Real Address Mode Exceptions
14440 STD‘‘Set Direction Flag
14442 Opcode Instruction Clocks Description
14444 FD STD 2 Set direction flag so SI and DI
14457 The direction flag is set to 1. This causes all subsequent string
14458 operations to decrement the index registers (SI and/or DI) on which they
14461 Protected Mode Exceptions
14465 Real Address Mode Exceptions
14470 STI‘‘Set Interrupt Enable Flag
14472 Opcode Instruction Clocks Description
14474 FB STI 2 Set interrupt enable flag,
14479 Interrupt=1 (enabled)
14487 The interrupts-enabled flag is set to 1. The 80286 will now respond to
14488 external interrupts after executing the STI instruction.
14490 Protected Mode Exceptions
14492 #GP(0) if the current privilege level is bigger (has less privilege) than
14493 the I/O privilege level.
14495 Real Address Mode Exceptions
14500 STOS/STOSB/STOSW‘‘Store String Data
14502 Opcode Instruction Clocks Description
14504 AA STOS mb 3 Store AL to byte ES:[DI], advance DI
14505 AB STOS mw 3 Store AX to word ES:[DI], advance DI
14506 AA STOSB 3 Store AL to byte ES:[DI], advance DI
14507 AB STOSW 3 Store AX to word ES:[DI], advance DI
14519 STOS transfers the contents the AL or AX register to the memory byte or
14520 word at ES:DI. The operand must be addressable from the ES register; no
14521 segment override is possible.
14523 After the transfer is made, DI is automatically advanced. If the direction
14524 flag is 0 (CLD was executed), DI increments; if the direction flag is 1 (STD
14525 was executed), DI decrements. DI increments or decrements by 1 if a byte was
14526 moved; by 2 if a word was moved.
14528 STOS can be preceded by the REP prefix for a block fill of CX bytes or
14529 words. Refer to the REP instruction for details of this operation.
14531 Protected Mode Exceptions
14533 #GP(0) if the destination is in a non-writable segment. #GP(0) for an
14534 illegal memory operand effective address in the CS, DS, or ES segments;
14535 #SS(0) for an illegal address in the SS segment.
14537 Real Address Mode Exceptions
14539 Interrupt 13 for a word operand at offset 0FFFFH.
14542 STR‘‘Store Task Register
14544 Opcode Instruction Clocks Description
14546 0F 00 /1 STR ew 2,mem=3 Store Task Register to EA word
14558 The contents of the Task Register are copied to the 2-byte register or
14559 memory location indicated by the effective address operand.
14561 Protected Mode Exceptions
14563 #GP(0) if the destination is in a non-writable segment. #GP(0) for an
14564 illegal memory operand effective address in the CS, DS, or ES segments;
14565 #SS(0) for an illegal address in the SS segment.
14567 Real Address Mode Exceptions
14569 Interrupt 6; STR is not recognized in Real Address mode.
14572 SUB‘‘Integer Subtraction
14574 Opcode Instruction Clocks Description
14576 28 /r SUB eb,rb 2,mem=7 Subtract byte register from EA byte
14577 29 /r SUB ew,rw 2,mem=7 Subtract word register from EA word
14578 2A /r SUB rb,eb 2,mem=7 Subtract EA byte from byte register
14579 2B /r SUB rw,ew 2,mem=7 Subtract EA word from word register
14580 2C db SUB AL,db 3 Subtract immediate byte from AL
14581 2D dw SUB AX,dw 3 Subtract immediate word from AX
14582 80 /5 db SUB eb,db 3,mem=7 Subtract immediate byte from EA byte
14583 81 /5 dw SUB ew,dw 3,mem=7 Subtract immediate word from EA word
14584 83 /5 db SUB ew,db 3,mem=7 Subtract immediate byte from
14589 Overflow, sign, zero, auxiliary carry, parity, carry
14597 The second operand is subtracted from the first operand, and the first
14598 operand is replaced with the result.
14600 When a byte-immediate value is subtracted from a word operand, the
14601 immediate value is firstsign-extended.
14603 Protected Mode Exceptions
14605 #GP(0) if the result is in a non-writable segment. #GP(0) for an illegal
14606 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
14607 an illegal address in the SS segment.
14609 Real Address Mode Exceptions
14611 Interrupt 13 for a word operand at offset 0FFFFH.
14614 TEST‘‘Logical Compare
14616 Opcode Instruction Clocks Description
14618 84 /r TEST eb,rb 2,mem=6 AND byte register into EA byte
14620 84 /r TEST rb,eb 2,mem=6 AND EA byte into byte register
14622 85 /r TEST ew,rw 2,mem=6 AND word register into EA word
14624 85 /r TEST rw,ew 2,mem=6 AND EA word into word register
14626 A8 db TEST AL,db 3 AND immediate byte into AL
14628 A9 dw TEST AX,dw 3 AND immediate word into AX
14630 F6 /0 db TEST eb,db 3,mem=6 AND immediate byte into EA byte
14632 F7 /0 dw TEST ew,dw 3,mem=6 AND immediate word into EA word
14637 Overflow=0, sign, zero, parity, carry=0
14645 TEST computes the bit-wise logical AND of the two operands given. Each bit
14646 of the result is 1 if both of the corresponding bits of the operands are 1;
14647 each bit is 0 otherwise. The result of the operation is discarded; only the
14648 flags are modified.
14650 Protected Mode Exceptions
14652 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
14653 segments; #SS(0) for an illegal address in the SS segment.
14655 Real Address Mode Exceptions
14657 Interrupt 13 for a word operand at offset 0FFFFH.
14660 VERR,VERW‘‘Verify a Segment for Reading or Writing
14662 Opcode Instruction Clocks Description
14664 0F 00 /4 VERR ew 14,mem=16 Set ZF=1 if seg. can be read,
14666 0F 00 /5 VERW ew 14,mem=16 Set ZF=1 if seg. can be written,
14679 VERR and VERW expect the 2-byte register or memory operand to contain the
14680 value of a selector. The instructions determine whether the segment denoted
14681 by the selector is reachable from the current privilege level; the
14682 instructions also determine whether it is readable or writable. If the
14683 segment is determined to be accessible, the zero flag is set to 1; if the
14684 segment is not accessible, it is set to 0. To set ZF, the following
14685 conditions must be met:
14687 1. The selector must denote a descriptor within the bounds of the table
14688 (GDT or LDT); that is, the selector must be "defined."
14690 2. The selector must denote the descriptor of a code or data segment.
14692 3. If the instruction is VERR, the segment must be readable. If the
14693 instruction is VERW, the segment must be a writable data segment.
14695 4. If the code segment is readable and conforming, the descriptor
14696 privilege level (DPL) can be any value for VERR. Otherwise, the DPL
14697 must be greater than or equal to (have less or the same privilege as)
14698 both the current privilege level and the selector's RPL.
14700 The validation performed is the same as if the segment were loaded into DS
14701 or ES and the indicated access (read or write) were performed. The zero flag
14702 receives the result of the validation. The selector's value cannot result in
14703 a protection exception. This enables the software to anticipate possible
14704 segment access problems.
14706 Protected Mode Exceptions
14708 The only faults that can occur are those generated by illegally addressing
14709 the memory operand which contains the selector. The selector is not loaded
14710 into any segment register, and no faults attributable to the selector
14711 operand are generated.
14713 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
14714 segments; #SS(0) for an illegal address in the SS segment.
14716 Real Address Mode Exceptions
14718 Interrupt 6; VERR and VERW are not recognized in Real Address Mode.
14721 WAIT‘‘Wait Until BUSY Pin Is Inactive (HIGH)
14723 Opcode Instruction Clocks Description
14725 9B WAIT 3 Wait until BUSY pin is inactive (HIGH)
14737 WAIT suspends execution of 80286 instructions until the BUSY pin is inactive
14738 (high). The BUSY pin is driven by the 80287 numeric processor extension.
14739 WAIT is issued to ensure that the numeric instruction being executed is
14740 complete, and to check for a possible numeric fault (see below).
14742 Protected Mode Exceptions
14744 #NM if task switch flag in MSW is set. #MF if 80287 has detected an
14745 unmasked numeric error.
14747 Real Address Mode Exceptions
14749 Same as Protected mode.
14752 XCHG‘‘Exchange Memory/Register with Register
14754 Opcode Instruction Clocks Description
14756 86 /r XCHG eb,rb 3,mem=5 Exchange byte register with EA byte
14757 86 /r XCHG rb,eb 3,mem=5 Exchange EA byte with byte register
14758 87 /r XCHG ew,rw 3,mem=5 Exchange word register with EA word
14759 87 /r XCHG rw,ew 3,mem=5 Exchange EA word with word register
14760 90+ rw XCHG AX,rw 3 Exchange word register with AX
14761 90+ rw XCHG rw,AX 3 Exchange with word register
14773 The two operands are exchanged. The order of the operands is immaterial.
14774 BUS LOCK is asserted for the duration of the exchange, regardless of the
14775 presence or absence of the LOCK prefix or IOPL.
14777 Protected Mode Exceptions
14779 #GP(0) if either operand is in a non-writable segment. #GP(0) for an
14780 illegal memory operand effective address in the CS, DS, or ES segments;
14781 #SS(0) for an illegal address in the SS segment.
14783 Real Address Mode Exceptions
14785 Interrupt 13 for a word operand at offset 0FFFFH.
14788 XLAT‘‘Table Look-up Translation
14790 Opcode Instruction Clocks Description
14792 D7 XLAT mb 5 Set AL to memory byte DS:[BX + unsigned AL]
14793 D7 XLATB 5 Set AL to memory byte DS:[BX + unsigned AL]
14805 When XLAT is executed, AL should be the unsigned index into a table
14806 addressed by DS:BX. XLAT changes the AL register from the table index into
14807 the table entry. BX is unchanged.
14809 Protected Mode Exceptions
14811 #GP(0) for an illegal memory operand effective address in the CS, DS, or ES
14812 segments; #SS(0) for an illegal address in the SS segment.
14814 Real Address Mode Exceptions
14816 Interrupt 13 for a word operand at offset 0FFFFH.
14819 XOR‘‘Logical Exclusive OR
14821 Opcode Instruction Clocks Description
14823 30 /r XOR eb,rb 2,mem=7 Exclusive-OR byte register into EA byte
14824 31 /r XOR ew,rw 2,mem=7 Exclusive-OR word register into EA word
14825 32 /r XOR rb,eb 2,mem=7 Exclusive-OR EA byte into byte register
14826 33 /r XOR rw,ew 2,mem=7 Exclusive-OR EA word into word register
14827 34 db XOR AL,db 3 Exclusive-OR immediate byte into AL
14828 35 dw XOR AX,dw 3 Exclusive-OR immediate word into AX
14829 80 /6 db XOR eb,db 3,mem=7 Exclusive-OR immediate byte into EA byte
14830 81 /6 dw XOR ew,dw 3,mem=7 Exclusive-OR immediate word into EA word
14834 Overflow=0, sign, zero, parity, carry=0
14842 XOR computes the exclusive OR of the two operands. Each bit of the result
14843 is 1 if the corresponding bits of the operands are different; each bit is 0
14844 if the corresponding bits are the same. The answer replaces the first
14847 Protected Mode Exceptions
14849 #GP(0) if the result is in a non-writable segment. #GP(0) for an illegal
14850 memory operand effective address in the CS, DS, or ES segments; #SS(0) for
14851 an illegal address in the SS segment.
14853 Real Address Mode Exceptions
14855 Interrupt 13 for a word operand at offset 0FFFFH.
14858 Appendix C 8086/8088 Compatibility Considerations
14860 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
14862 Software Compatibility Considerations
14864 In general, the real address mode 80286 will correctly execute ROM-based
14865 8086/8088 software. The following is a list of the minor differences between
14866 8086 and 80286 (Real mode).
14868 1. Add Six Interrupt Vectors. The 80286 adds six interrupts which arise
14869 only if the 8086 program has a hidden bug. These interrupts occur only
14870 for instructions which were undefined on the 8086/8088 or if a segment
14871 wraparound is attempted. It is recommended that you add an interrupt
14872 handler to the 8086 software that is to be run on the 80286, which
14873 will treat these interrupts as invalid operations. This additional
14874 software does not significantly effect the existing 8086 software
14875 because the interrupts do not normally occur and should not already
14876 have been used since they are in the interrupt group reserved by
14877 Intel. Table C-1 describes the new 80286 interrupts.
14879 2. Do not Rely on 8086/8088 Instruction Clock Counts. The 80286 takes
14880 fewer clocks for most instructions than the 8086/8088. The areas to
14881 look into are delays between I/O operations, and assumed delays in
14882 8086/8088 operating in parallel with an 8087.
14884 3. Divide Exceptions Point at the DIV Instruction. Any interrupt on the
14885 80286 will always leave the saved CS:IP value pointing at the
14886 beginning of the instruction that failed (including prefixes). On the
14887 8086, the CS:IP value saved for a divide exception points at the next
14890 4. Use Interrupt 16 for Numeric Exceptions. Any 80287 system must use
14891 interrupt vector 16 for the numeric error interrupt. If an 8086/8087
14892 or 8088/8087 system uses another vector for the 8087 interrupt, both
14893 vectors should point at the numeric error interrupt handler.
14895 5. Numeric Exception Handlers Should allow Prefixes. The saved CS:IP
14896 value in the NPX environment save area will point at any leading
14897 prefixes before an ESC instruction. On 8086/8088 systems, this value
14898 points only at the ESC instruction.
14900 6. Do Not Attempt Undefined 8086/8088 Operations. Instructions like
14901 POP CS or MOV CS,op will either cause exception 6 (undefined opcode)
14902 or perform a protection setup operation like LIDT on the 80286.
14903 Undefined bit encodings for bits 5-3 of the second byte of POP MEM or
14904 PUSH MEM will cause exception 13 on the 80286.
14906 7. Place a Far JMP Instruction at FFFF0H. After reset, CS:IP = F000:FFF0
14907 on the 80286 (versus FFFF:0000 on the 8086/8088). This change was made
14908 to allow sufficient code space to enter protected mode without
14909 reloading CS. Placing a far JMP instruction at FFFF0H will avoid this
14910 difference. Note that the BOOTSTRAP option of LOC86 will automatically
14911 generate this jump instruction.
14913 8. Do not Rely on the Value Written by PUSH SP. The 80286 will push a
14914 different value on the stack for PUSH SP than the 8086/8088. If the
14915 value pushed is important, replace PUSH SP instructions with the
14916 following three instructions:
14920 This code functions as the 8086/8088 PUSH SP instruction on the 80286.
14922 9. Do not Shift or Rotate by More than 31 Bits. The 80286 masks all
14923 shift/rotate counts to the low 5 bits. This MOD 32 operation limits
14924 the count to a maximum of 31 bits. With this change, the longest
14925 shift/rotate instruction is 39 clocks. Without this change, the
14926 longest shift/rotate instruction would be 264 clocks, which delays
14927 interrupt response until the instruction completes execution.
14929 10. Do not Duplicate Prefixes. The 80286 sets an instruction length limit
14930 of 10 bytes. The only way to violate this limit is by duplicating a
14931 prefix two or more times before an instruction. Exception 6 occurs if
14932 the instruction length limit is violated. The 8086/8088 has no
14933 instruction length limit.
14935 11. Do not Rely on Odd 8086/8088 LOCK Characteristics. The LOCK prefix and
14936 its corresponding output signal should only be used to prevent other
14937 bus masters from interrupting a data movement operation. The 80286
14938 will always assert LOCK during an XCHG instruction with memory (even
14939 if the LOCK prefix was not used). LOCK should only be used with the
14940 XCHG, MOV, MOVS, INS, and OUTS instructions. The 80286 LOCK signal
14941 will not go active during an instruction prefetch.
14943 12. Do not Single Step External Interrupt Handlers. The priority of the
14944 80286 single step interrupt is different from that of the 8086/8088.
14945 This change was made to prevent an external interrupt from being
14946 single-stepped if it occurs while single stepping through a program.
14947 The 80286 single step interrupt has higher priority than any external
14948 interrupt. The 80286 will still single step through an interrupt
14949 handler invoked by INT instructions or an instruction exception.
14951 13. Do not Rely on IDIV Exceptions for Quotients of 80H or 8000H. The
14952 80286 can generate the largest negative number as a quotient for IDIV
14953 instructions. The 8086 will instead cause exception 0.
14955 14. Do not Rely on NMI Interrupting NMI Handlers. After an NMI is
14956 recognized, the NMI input and processor extension limit error
14957 interrupt is masked until the first IRET instruction is executed.
14959 15. The NPX error signal does not pass through an interrupt controller
14960 (an 8087 INT signal does). Any interrupt controller-oriented
14961 instructions for the 8087 may have to be deleted.
14963 16. If any real-mode program relies on address space wrap-around (e.g.,
14964 FFF0:0400=0000:0300), then external hardware should be used to force
14965 the upper 4 addresses to zero during real mode.
14967 17. Do not use I/O ports 00F8-00FFH. These are reserved for controlling
14968 80287 and future processor extensions.
14971 Table C-1. New 80286 Interrupts
14976 5 A BOUND instruction was executed with a register value outside
14977 the two limit values.
14978 6 An undefined opcode was encountered.
14979 7 The EM bit in the MSW has been set and an ESC instruction was
14980 executed. This interrupt will also occur on WAIT instructions
14982 8 The interrupt table limit was changed by the LIDT instruction
14983 to a value between 20H and 43H. The default limit after reset is
14984 3FFH, enough for all 256 interrupts.
14985 9 A processor extension data transfer exceeded offset 0FFFFH in a
14986 segment. This interrupt handler must execute FNINIT before
14987 any ESC or WAIT instruction is executed.
14988 13 Segment wraparound was attempted by a word operation at offset
14990 16 When 80286 attempted to execute a coprocessor instruction
14991 ERROR pin indicated an unmasked exception from previous
14992 coprocessor instruction.
14995 Hardware Compatibility Considerations
14997 1. Address after Reset
14999 8086 has CS:IP = FFFF:0000 and physical address FFFF0.
15000 80286 has CS:IP = F000:FFF0 and physical address FFFFF0.
15002 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15004 After 80286 reset, until the first 80286 far JMP or far CALL, the
15005 code segment base is FF0000. This means A20-A23 will be high for
15006 CS-relative bus cycles (code fetch or use of CS override prefix)
15007 after reset until the first far JMP or far CALL instruction is
15009 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15011 2. Physical Address Formation
15013 In real mode or protected mode, the 80286 always forms a physical
15014 address by adding a 16-bit offset with a 24-bit segment base value
15015 (8086 has 20-bit base value). Therefore, if the 80286 in real mode
15016 has a segment base within 64K of the top of the 1 Mbyte address space,
15017 and the program adds an offset of ffffh to the segment base, the
15018 physical address will be slightly above 1Mbyte. Thus, to fully
15019 duplicate 1Mbyte wraparound that the 8086 has, it is always necessary
15020 to force A20 low externally when the 80286 is in real mode, but system
15021 hardware uses all 24 address lines.
15025 On the 8086, LOCK asserted means this bus cycle is within a group of
15026 two or more locked bus cycles. On the 80286, the LOCK signal means
15027 lock this bus cycle to the NEXT bus cycle. Therefore, on the 80286,
15028 the LOCK signal is not asserted on the last locked bus cycle of the
15029 group of locked bus cycles.
15031 4. Coprocessor Interface
15033 8086, synchronous to 8086, can become a bus master.
15034 80287, asynchronous to 80286 and 80287, cannot become a bus master.
15035 8087 pulls opcode and pointer information directly from data bus.
15036 80286 passes opcode and pointer information to 80287.
15037 8087 uses interrupt path to signal errors to 8086.
15038 80287 uses dedicated ERROR signal.
15039 8086 requires explicit WAIT opcode preceding all ESC instructions to
15040 synchronize with 8087. 80286 has automatic instruction synchronization
15045 8086 has four-clock minimum bus cycle, with a time-multiplexed
15046 address/data bus. 80286 has two-clock minimum bus cycle, with separate
15047 buses for address and data.
15050 Appendix D 80286/80386 Software Compatibility Considerations
15052 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15054 This appendix describes the considerations required in designing an
15055 Operating System for the protected mode 80286 so that it will operate
15056 on an 80386. An 80286 Operating System running on the 80386 would not use
15057 any of the advanced features of the 80386 (i.e., paging or segments larger
15058 than 64K), but would run 80286 code faster. Use of the new 80386 features
15059 requires changes in the 80286Operating System.
15061 The 80386 is no different than any other software compatible processor in
15062 terms of requiring the same system environment to run the same software; the
15063 80386 must have the same amount of physical memory and I/O devices in the
15064 system as the 80286 system to run the same software. Note that an 80386
15065 system requires a different memory system to achieve the higher
15068 The 80286 design considerations can be generally characterized as avoiding
15069 use of functions or memory that the 80386 will use. The exception to this
15070 rule is initialization code executed after power up. Such code must be
15071 changed to configure the 80386 system to match that of the 80286 system.
15073 The following are 80286/80386 software compatibility design considerations:
15075 1. Isolate the protected mode initialization code.
15077 System initialization code will be required on the 80386 to program
15078 operating parameters before executing any significant amount of 80286
15079 software. The 80286 initialization software should be isolated from
15080 the rest of the Operating System.
15082 The initialization code in Appendix A is an example of isolated
15083 initialization code. Such code can be extended to include programming
15084 of operating parameters before executing the initial protected
15087 2. Avoid wraparound of 80286 24-bit physical address space.
15089 Since the 80386 has a larger physical address space, any segment
15090 whose base address is greater than FF0000 and whose limit is beyond
15091 FFFFFF will address the seventeenth megabyte of memory in the 80386
15092 32-bit physical address space instead of the first megabyte on an
15095 No expand-down segments shouldhave a base address in the range
15096 FF00001-FFFFFF. No expand-up segments should wrap around the 80286
15097 address space (the sum of their base and limit is in the range
15100 3. Zero the last word of every 80286 descriptor.
15102 The 80386 uses the last word of each descriptor to expand the base
15103 address and limit fields of segments. Placing zeros in the descriptor
15104 will cause the 80386 to treat the segments the same way as an 80286
15105 (except for address space wraparound as mentioned above).
15107 4. Use only 80H or 00H for invalid descriptors.
15109 The 80386 uses more descriptor types than the 80286. Numeric values
15110 of 8-15 in bits 3-0 of the access byte for control descriptors will
15111 cause a protection exception on the 80286, but may be defined for
15112 other segment types on the 80386. Access byte values of 80H and 00H
15113 will remain undefined descriptors on both the 80286 and the 80386.
15115 5. Put error interrupt handlers in reserved interrupts 14, 15, 17-31.
15117 Some of the unused, Intel-reserved interrupts of the 80286
15118 will be used by the 80386 (i.e., page fault or bus error). These
15119 interrupts should not occur while executing an 80286 operating system
15120 on an 80386. However, it is safest to place an interrupt handler in
15121 these interrupts to print an error message and stop the system if
15124 6. Do not change bits 15-4 of MSW.
15126 The 80386 uses some of the undefined bits in the machine status word.
15127 80286 software should ignore bits 15-4 of the MSW. To change the MSW
15128 on an 80286, read the old value first with LMSW, change bits 3-0 only,
15129 then write the new value with SMSW.
15131 7. Use a restricted LOCK protocol for multiprocessor systems.
15133 The 80386 supports the 8086/80286 LOCK functions for simple
15134 instructions, but not the string move instructions. Any need for
15135 locked string moves can be satisfied by gaining control of a status
15136 semaphore before using the string move instruction. Any attempt to
15137 execute a locked string move will cause a protection exception on the
15140 The general 80286 LOCK protocol does not efficiently extend to large
15141 multiprocessor systems. If all the processors in the system frequently
15142 use the 8086/80286 LOCK, they will prevent other processors from
15143 accessing memory and thereby impact system performance.
15145 Access to semaphores in the future, including current 80286 Operating
15146 Systems, should use a protocol with the following restrictions:
15148 Ž Be sure the semaphore starts at a physical memory address that is a
15151 Ž Do not use string moves to access the variable.
15153 Ž All accesses by any instruction or I/O device (even simple reads or
15154 writes) must use the LOCK prefix or system LOCK signal.
15158 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15161 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15170 Based Indexed Mode with Displacement
15171 Based Mode (on BX or BP Registers)
15172 Direct Address Mode
15175 Indexed Mode (by DI or SI)
15177 Register Indirect Mode
15179 AF Flag, (see Flags)
15183 Arithmetic Instructions
15184 ASCII (see Data Types)
15189 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15190 Based Index Mode (see Addressing Modes)
15191 Based Index Mode with Displacement (see Addressing Modes)
15192 Based Mode (see Addressing Modes)
15193 BCD Arithmetic (see Data Management Instructions)
15196 BOUND Instruction (see Extended Instruction Set)
15197 Bound Range Exceeded (Interrupt 5), (see Interrupt Handling)
15199 Breakpoint Interrupt 3, (see Interrupt Handling)
15203 Byte (See Data Types)
15207 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15211 CF (Carry Flag) (see Flags)
15219 Code Segment Access
15220 Comparison Instructions
15221 Conforming Code Segments
15222 Constant Instructions
15224 CPL (Current Privilege Level)
15231 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15234 Data Management Instructions
15235 Address Manipulation
15236 Arithmetic Instructions
15237 Addition Instructions
15238 Division Instructions
15239 Multiplication Instructions
15240 Subtraction Instructions
15242 Character Transfer and String Instructions
15246 Control Transfer Instructions
15247 Conditional Transfer
15248 Software Generated Interrupts
15249 Interrupt Instructions
15250 Unconditional Transfer
15252 Logical Instructions
15253 Shift and Rotate Instructions
15254 Type Conversion Instructions
15255 Processor Extension Intructions
15256 Test and Compare Instructions
15257 Trusted Instructions
15258 Input/Output Instructions
15260 Data Transfer Instructions
15272 Dedicated Interrupt Vector
15274 Descriptor Table Register
15275 DF Flag, (see Flags)
15278 Direct Address Mode (see Addressing Modes)
15279 Divide Error (Interrupt 0) (see Interrupt Handling)
15282 DPL (Descriptor Privilege Level)
15288 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15292 ESC (Instructions for Coprocessor)
15293 Extended Instruction Set (Chapter 4)
15294 ENTER Build Stackframe
15295 LEAVE Remove Stackframe
15296 Repeated IN and OUT String Instructions
15300 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15302 Flags see also Use of Flags with Basic
15304 AF (Auxilliary Carry Flag)
15307 DF (Direction Flag)
15308 IF (Interrupt Flag)
15309 IOPL (Privilege Level)
15310 NT (Nested Task Flag)
15317 Floating Point (see Data Types)
15321 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15324 GDTR (Global Descriptor Register)
15325 General Protection Fault (Interrupt 3), (see Interrupt Handling)
15330 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15332 Hierarchy of 86, 186, 286 Instruction Sets
15333 Basic Instruction Set, Chapter 3
15334 Extended Instruction Set
15335 Instruction Set Overview
15336 System Control Register Set, Chapter 4, Chapter 5, Chapter 6, Chapter 7
15337 (cont.) Chapter 8, Chapter 9, Chapter 10
15341 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15344 IDT (Interrupt Descriptor Table)
15345 IDTR (Interrupt Descriptor Table Register)
15346 IF (Interrupt Flag), (see Flags)
15352 Index, Pointer and Base Register
15356 Restrictions in Protected Mode
15358 INS/INSB/INSW Instruction
15359 INT Instruction, (see Interrupt Handling)
15360 Integer, (see Data Types)
15363 Interrupt Priorities
15364 Interrupt 0 Divide Error
15365 Interrupt 1 Single-Step
15366 Interrupt 2 Nonmaskable
15367 Interrupt 3 Breakpoint
15368 Interrupt 4 INTO Detected Overflow
15369 Interrupt 5 BOUND Range Exceeded
15370 Interrupt 6 Invalid Opcode
15371 Interrupt 7 Processor Extension Not Available
15372 Interrupt 8, Interrupt Table Limit Too Small
15375 Interrupt Vector Table
15376 Interrupts and Exceptions,(see Interrupt Handling and Interrupt Priorities)
15377 INTO Detected Overflow (Interrupt 4), (see Interrupt Handling and Interrupt
15381 Invalid opcode (Interrupt 6), (see Interrupt Handling and Interrupt
15383 IOPL (I/O Privilege Level), (see Flags)
15389 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15395 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15399 LDT (Local Descriptor Table)
15418 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15423 Interpretation in Protected Mode
15424 Interpretation in Real Mode
15427 Memory Addressing Modes
15429 Task Managment, Chapter 8
15430 Context Switching (Task Switching)
15432 Memory Management Registers, Chapter 6
15433 Memory Mapped I/O, (see Input/Output)
15435 Memory Segmentation and Segment Registers
15445 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15447 NMI (Non maskable Interrupt)
15448 Nonmaskable (Interrupt 2), (see Interrupt Priorities)
15451 Not Present (Interrupt 11) (see Interrupt Priorities)
15452 NPX Processor Extension
15453 NT (Nested Task Flag), (see Flags)
15454 Numeric Data Processor Instructions
15458 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15459 OF (Overflow Flag), (see Flags)
15464 OUTS/OUTSB/OUTSW Instruction
15468 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15469 PF (Parity Flag), (see Flags)
15470 Pointer, (see Data Types)
15474 Processor Extension Error (Interrupt 6), (see Interrupt Handling and
15475 Interrupt Priorities)
15476 Processor Extension Not Available, (Interrupt 7), (see Interrupt and
15477 Interrupt Priorities)
15478 Processor Extension Segment Overrun Interrupt (Interrupt 9), (see Interrupt
15479 and Interrupt Priorities)
15481 Protected Virtual Address Mode
15482 Protection Implementation
15483 Protection Mechanisms
15490 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15493 Base Architecture Diagram
15497 Index Registers DI, SI
15499 Pointer Registers BP and SP
15502 Register Direct Mode
15503 Register and Immediate Modes
15504 Register Indirect Mode (see Addressing Modes)
15505 Reserved Interrupt Vectors, (see Interrupt Handling and Interrupt
15522 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15527 SEG (Segment Override Prefix)
15528 Segment Address Translation Registers
15530 Segment Overrun Exception (Interrupt 13), (see Interrupt Handling and
15531 Interrupt Priorities)
15533 SF (Sign Flag), (see Flags)
15539 Single Step (Interrupt 1), (see Interrupt Priorities)
15544 Status and Control Registers
15545 Stack Flag, (see Flags)
15546 Stack Fault (Interrupt 12), (see Interrupt Priorities)
15547 Stack Manipulation Instructions
15551 Segment Register Usage
15552 Segment Usage Override
15553 Stack Frame Base Pointer BP
15556 with BP and SP Registers
15561 String Instructions
15563 System Address Registers
15564 System Initialization
15565 System Control Instructions
15569 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15571 TF (Trap Flags), (see Flags)
15572 TOS (Top of Stack), (see Stack Operation)
15574 Transcendental Instruction
15575 TSS (Task State Segment)
15579 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15580 Use of Flags with Basic Instructions
15584 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15589 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
15594 ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘